Class: Wurk::Worker::Setter
- Inherits:
-
Object
- Object
- Wurk::Worker::Setter
- 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
-
#initialize(klass, opts) ⇒ Setter
constructor
A new instance of Setter.
- #perform_async(*args) ⇒ Object
- #perform_bulk(args, **opts) ⇒ Object
- #perform_in(interval, *args) ⇒ Object (also: #perform_at)
-
#perform_inline(*args) ⇒ Object
(also: #perform_sync)
Explicit synchronous execution.
- #set(options) ⇒ Object
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
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/wurk/worker/setter.rb', line 63 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.['pool'] @klass.build_client(pool).push_bulk(merged) end |
#perform_in(interval, *args) ⇒ Object Also known as: perform_at
55 56 57 58 59 60 |
# File 'lib/wurk/worker/setter.rb', line 55 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_inline(*args) ⇒ Object Also known as: perform_sync
Explicit synchronous execution. Runs the payload through the real client
AND server middleware chains rather than calling perform directly:
unique-job locks are taken by the client chain and released only by the
server chain (bypassing both leaked every lock until its TTL), and batch
callbacks fire from server middleware. Mirrors Sidekiq's Setter#perform_inline,
including its return contract — nil when middleware halts the job, else true.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/wurk/worker/setter.rb', line 40 def perform_inline(*args) config = Wurk.configuration item = normalize_item(@opts.merge('class' => @klass, 'args' => args)) pushed = config.client_middleware.invoke(item['class'], item, item['queue'], config.redis_pool) do verify_json(item) item end return nil unless pushed # Round-trip through JSON so the job sees exactly the arguments a real # worker would after the payload has crossed Redis. run_job(Wurk.load_json(Wurk.dump_json(item)), config) end |
#set(options) ⇒ Object
23 24 25 26 |
# File 'lib/wurk/worker/setter.rb', line 23 def set() @opts.merge!(normalize_opts()) self end |