Method: WarpCore.dispatch_in

Defined in:
lib/warpcore/sidekiq.rb

.dispatch_in(worker_name, *args) ⇒ Object

Asynchronously dispatch a Sidekiq worker at a later time with the provided arguments. This is equivalent to calling the worker directly with perform_in.

Examples:

WarpCore.dispatch_in 'Workers::MyWorker', 10.seconds, argument1, argument2.....

Parameters:

  • args (Array)

    the arguments to pass to the worker. The first argument should be the amount of time to wait before dispatching the worker.

  • worker_name (String)

    the full class path of the worker (ex. Workers::MyWorker)



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/warpcore/sidekiq.rb', line 40

def self.dispatch_in(worker_name, *args)
  klass = worker_name.constantize
  if klass.respond_to?(:perform_async)
    puts "=> [Dispatch:Delay] #{worker_name}"
    return klass.perform_in(*args)
  else
    warn "Dispatched #{worker_name} not a valid Sidekiq worker."
    nil
  end
rescue NameError => e
  puts "Worker [#{worker_name}] not defined."
  nil
end