Class: SuckerPunch::Backgroundable::JobRunner

Inherits:
Object
  • Object
show all
Includes:
CallMethod
Defined in:
lib/sucker_punch/backgroundable/job.rb

Instance Method Summary collapse

Constructor Details

#initialize(receiver, method, args, options) ⇒ JobRunner

Returns a new instance of JobRunner.



45
46
47
# File 'lib/sucker_punch/backgroundable/job.rb', line 45

def initialize(receiver, method, args, options)
  @receiver, @method, @args, @options = receiver, method, args, options
end

Instance Method Details

#run(seconds = 0) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sucker_punch/backgroundable/job.rb', line 49

def run(seconds = 0)
  if SuckerPunch::Backgroundable.configuration.enabled
    # run as SuckerPunch Job
    if seconds > 0
      Job.perform_in(seconds, @receiver, @method, @args, @options)
    else
      Job.perform_async(@receiver, @method, @args, @options)
    end
  else
    # run without SuckerPunch or Celluloid
    @receiver = load(@receiver) if instantiate?(@options)
    call(@receiver, @method, *@args)
  end
end