Module: Wurk::Worker
- Defined in:
- lib/wurk/worker.rb,
lib/wurk/worker/setter.rb
Overview
The user-facing DSL: ‘include Wurk::Worker` (aliased to Sidekiq::Worker). Owns `sidekiq_options`, `perform_async`, `perform_in`, `perform_at`, `set`, `sidekiq_retry_in`, etc.
Spec: docs/target/sidekiq-free.md §6 (Sidekiq::Job).
Defined Under Namespace
Modules: ClassMethods Classes: Setter
Constant Summary collapse
- SCHEDULED_THRESHOLD =
Interval values below this threshold are interpreted as seconds-from-now; values at or above are treated as absolute epoch timestamps. Threshold matches Sidekiq exactly — wire-compat sacred.
1_000_000_000
Instance Attribute Summary collapse
-
#bid ⇒ Object
Batch helpers (Pro).
Class Method Summary collapse
- .clear_all ⇒ Object
- .drain_all ⇒ Object
- .included(base) ⇒ Object
-
.jobs ⇒ Object
Module-level test helpers: ‘Sidekiq::Worker.jobs / clear_all / drain_all` operate across every job class (spec §24.3).
Instance Method Summary collapse
- #batch ⇒ Object
-
#interrupted? ⇒ Boolean
Cooperative cancellation flag for IterableJob and long-running jobs.
- #logger ⇒ Object
-
#valid_within_batch? ⇒ Boolean
False if the batch was invalidated.
Instance Attribute Details
#bid ⇒ Object
Batch helpers (Pro). Available on every worker — return nil when the current job did not originate from a batch.
Spec: docs/target/sidekiq-pro.md §2.6.
47 48 49 |
# File 'lib/wurk/worker.rb', line 47 def bid @bid end |
Class Method Details
.clear_all ⇒ Object
29 |
# File 'lib/wurk/worker.rb', line 29 def self.clear_all = ::Wurk::Queues.clear_all |
.drain_all ⇒ Object
30 |
# File 'lib/wurk/worker.rb', line 30 def self.drain_all = ::Wurk::Testing.drain_all |
.included(base) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/wurk/worker.rb', line 17 def self.included(base) base.extend(ClassMethods) base.module_eval { attr_accessor :jid, :_context } base.singleton_class.module_eval do attr_accessor :sidekiq_retry_in_block, :sidekiq_retries_exhausted_block end end |
Instance Method Details
#batch ⇒ Object
54 55 56 57 58 |
# File 'lib/wurk/worker.rb', line 54 def batch return nil if @bid.nil? Wurk::Batch.new(@bid) end |
#interrupted? ⇒ Boolean
Cooperative cancellation flag for IterableJob and long-running jobs. Returns false when no processor context has been attached.
38 39 40 41 |
# File 'lib/wurk/worker.rb', line 38 def interrupted? ctx = @_context ctx.respond_to?(:stopping?) && ctx.stopping? end |
#valid_within_batch? ⇒ Boolean
False if the batch was invalidated. Workers should ‘return unless valid_within_batch?` to short-circuit work for cancelled batches.
62 63 64 65 66 |
# File 'lib/wurk/worker.rb', line 62 def valid_within_batch? return true if @bid.nil? batch.valid? end |