Created
February 22, 2013 16:48
-
-
Save dip00dip/5014826 to your computer and use it in GitHub Desktop.
API method for adding a job for background processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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