Class: Wurk::Worker::Setter

Inherits:
Object
  • Object
show all
Includes:
JobUtil
Defined in:
lib/wurk/worker/setter.rb

Overview

Aliased as ‘Sidekiq::Job::Setter`. Per-call option carrier returned by `Worker.set(opts)`. Holds string-keyed overrides and exposes the same `perform_*` surface as the worker class itself.

‘set(sync: true)` makes `perform_async` invoke `perform_inline` —required for testing-mode parity.

Spec: docs/target/sidekiq-free.md §6.3 (Sidekiq::Job::Setter).

Constant Summary

Constants included from JobUtil

JobUtil::RETRY_FOR_MAX, JobUtil::TRANSIENT_ATTRIBUTES

Instance Method Summary collapse

Methods included from JobUtil

#normalize_item, #now_in_millis, #validate, #verify_json

Constructor Details

#initialize(klass, opts) ⇒ Setter

Returns a new instance of Setter.



18
19
20
21
# File 'lib/wurk/worker/setter.rb', line 18

def initialize(klass, opts)
  @klass = klass
  @opts = normalize_opts(opts)
end

Instance Method Details

#perform_async(*args) ⇒ Object



28
29
30
31
32
# File 'lib/wurk/worker/setter.rb', line 28

def perform_async(*args)
  return perform_inline(*args) if @opts['sync']

  @klass.client_push(@opts.merge('class' => @klass, 'args' => args))
end

#perform_bulk(args, **opts) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/wurk/worker/setter.rb', line 47

def perform_bulk(args, **opts)
  merged = @opts.merge(opts.transform_keys(&:to_s)).merge(
    'class' => @klass,
    'args' => args
  )
  @klass.build_client.push_bulk(merged)
end

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



39
40
41
42
43
44
# File 'lib/wurk/worker/setter.rb', line 39

def perform_in(interval, *args)
  ts = absolute_at(interval)
  item = @opts.merge('class' => @klass, 'args' => args)
  item['at'] = ts if ts && ts > now_seconds
  @klass.client_push(item)
end

#perform_inlineObject Also known as: perform_sync



34
35
36
# File 'lib/wurk/worker/setter.rb', line 34

def perform_inline(*)
  @klass.new.perform(*)
end

#set(options) ⇒ Object



23
24
25
26
# File 'lib/wurk/worker/setter.rb', line 23

def set(options)
  @opts.merge!(normalize_opts(options))
  self
end