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).

Instance Method Summary collapse

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

#normalize_item(item) ⇒ Object Originally defined in module JobUtil

Validate → merge class/default options → stringify → assign jid & created_at → strip transient keys. Returns the canonical payload.

#now_in_millisObject Originally defined in module JobUtil

#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
54
55
56
57
# 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
  )
  # Mirror client_push: a per-call `set(pool:)` selects the Redis pool and
  # is removed so it never persists (normalize_item strips the class-level
  # pool re-merged into each payload).
  pool = merged.delete('pool') || @klass.get_sidekiq_options['pool']
  @klass.build_client(pool).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

#validate(item) ⇒ Object Originally defined in module JobUtil

Raises:

  • (ArgumentError)

    if the payload is structurally invalid.

#verify_json(item) ⇒ Object Originally defined in module JobUtil

Walk args; report the first non-JSON-native value according to the configured strict mode. Hash keys must be Strings.