Module: Shoryuken::Later::Worker::ClassMethods

Defined in:
lib/shoryuken/later/worker.rb

Instance Method Summary collapse

Instance Method Details

#perform_later(time, body, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/shoryuken/later/worker.rb', line 9

def perform_later(time, body, options = {})
  time = Time.now + time.to_i if time.is_a?(Numeric)
  time = time.to_time if time.respond_to?(:to_time)
  raise ArgumentError, 'expected Numeric, Time but got '+time.class.name unless Time===time
  
  # Times that are less than 15 minutes in the future can be queued immediately.
  if time < Time.now + Shoryuken::Later::MAX_QUEUE_DELAY
    perform_in(time, body, options)
    
  # Otherwise, the message is inserted into a DynamoDB table with the same name as the queue.
  else
    table = get_shoryuken_options['schedule_table'] || Shoryuken::Later.default_table
    args = JSON.dump(body: body, options: options)
    Shoryuken::Later::Client.create_item(table, perform_at: time.to_i, shoryuken_args: args,
                                                shoryuken_class: self.to_s)
  end
end