Class: GovernorBackground::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/governor_background/handler.rb

Class Method Summary collapse

Class Method Details

.run_in_background(job_name, *arguments) ⇒ Object

Handles incoming jobs, routes them to Delayed_Job or Resque (whichever one is installed within the app), and adds them to the JobManager.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/governor_background/handler.rb', line 6

def run_in_background(job_name, *arguments)
  job = if delayed_job?
    Delayed::Job.new(job_name, ::Delayed::Job.enqueue(Delayed::Performer.new(job_name, arguments)))
  elsif resque?
    resque_args = arguments.map do |arg|
      arg.is_a?(ActiveRecord::Base) ? Resque::Resource.new(arg) : arg
    end
    if resque_with_status?
      Resque::Job.new(job_name, Resque::PerformerWithState.create(:job_name => job_name, :arguments => resque_args))
    else
      ::Resque.enqueue(Resque::Performer, job_name, *resque_args)
      nil # not much use in holding on to state if we can't track it
    end
  end
  JobManager.add(job) if job
end