Class: Faktory::Job::Setter

Inherits:
Object
  • Object
show all
Defined in:
lib/faktory/job.rb

Overview

This helper class encapsulates the set options for ‘set`, e.g.

SomeJob.set(queue: 'foo').perform_async(....)

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Setter

Returns a new instance of Setter.



40
41
42
# File 'lib/faktory/job.rb', line 40

def initialize(opts)
  @opts = opts
end

Instance Method Details

#perform_async(*args) ⇒ Object



44
45
46
# File 'lib/faktory/job.rb', line 44

def perform_async(*args)
  @opts['jobtype'.freeze].client_push(@opts.merge!('args'.freeze => args))
end

#perform_in(interval, *args) ⇒ Object Also known as: perform_at

interval must be a timestamp, numeric or something that acts

numeric (like an activesupport time interval).


50
51
52
53
54
55
56
57
58
59
60
# File 'lib/faktory/job.rb', line 50

def perform_in(interval, *args)
  int = interval.to_f
  now = Time.now.to_f
  ts = (int < 1_000_000_000 ? now + int : int)
  at = Time.at(ts).utc.to_datetime.rfc3339(9)

  @opts.merge! 'args'.freeze => args, 'at'.freeze => at
  # Optimization to enqueue something now that is scheduled to go out now or in the past
  @opts.delete('at'.freeze) if ts <= now
  @opts['jobtype'.freeze].client_push(@opts)
end