Module: Dynamiq::Worker::ClassMethods

Defined in:
lib/dynamiq/worker.rb

Instance Method Summary collapse

Instance Method Details

#client_push(item) ⇒ Object

:nodoc:



34
35
36
37
# File 'lib/dynamiq/worker.rb', line 34

def client_push(item) # :nodoc:
  pool = Thread.current[:sidekiq_via_pool] || get_sidekiq_options['pool'] || Sidekiq.redis_pool
  Dynamiq::Client.new(pool).push(item.stringify_keys)
end

#perform_async(score, *args) ⇒ Object



16
17
18
# File 'lib/dynamiq/worker.rb', line 16

def perform_async(score, *args)
  client_push score: score, class: self, args: args
end

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



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dynamiq/worker.rb', line 20

def perform_in(interval, score, *args)
  int = interval.to_f
  now = Time.now.to_f
  ts = (int < 1_000_000_000 ? now + int : int)

  item = { score: score, class: self, args: args, at: ts }

  # Optimization to enqueue something now that is scheduled to go out now or in the past
  item.delete 'at' if ts <= now

  client_push item
end