Skip to content

Instantly share code, notes, and snippets.

@dip00dip
Created February 22, 2013 16:48
Show Gist options
  • Save dip00dip/5014826 to your computer and use it in GitHub Desktop.
Save dip00dip/5014826 to your computer and use it in GitHub Desktop.
API method for adding a job for background processing
class Api::DelayedController < ApplicationController
# Public: Adds a delayed job into queue.
#
# params[:task] - The class name of the job.
#
def add
job = params[:task].constantize
Sidekiq::Client.enqueue job if Object.const_defined?(Sidekiq::Client)
Delayed::Job.enqueue job.new if Object.const_defined?(Delayed::Job)
render :text => "Background job queued", :status => :created
rescue => e
render :text => "Error: #{e.message}", :status => :bad_request
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment