Module: Sidekiq::Callbacks
- Extended by:
- ActiveSupport::Concern
- Included in:
- Workarea::ApplicationDocument
- Defined in:
- app/workers/sidekiq/callbacks.rb
Overview
A plugin for Sidekiq
that enables automatic job enqueuing via Rails callback methods. Mix Sidekiq::Callbacks
into your model to enable this feature on any class that defines run_callbacks
.
Defined Under Namespace
Classes: InvalidConfiguration
Class Method Summary collapse
-
.assert_valid_config! ⇒ Object
This method is run on boot to ensure a valid configuration of callback workers.
-
.async(worker, ...) ⇒ Object
Permanently or temporarily inline callback workers.
-
.disable(worker, ...) ⇒ Object
Permanently or temporarily disable callback workers.
-
.enable(worker, ...) ⇒ Object
Permanently or temporarily enable callback workers.
-
.inline(worker, ...) ⇒ Object
Permanently or temporarily inline callback workers.
Instance Method Summary collapse
Class Method Details
.assert_valid_config! ⇒ Object
This method is run on boot to ensure a valid configuration of callback workers. It will raise a Sidekiq::Callbacks::InvalidConfiguration if it finds a problem.
150 151 152 153 154 155 156 157 158 159 |
# File 'app/workers/sidekiq/callbacks.rb', line 150 def assert_valid_config! Sidekiq::CallbacksWorker.workers.each do |worker| if (worker.enqueue_on.values.flatten & [:find, 'find']).any? raise( InvalidConfiguration, "For performance reasons, Sidekiq::Callbacks do not support the `find` callback." ) end end end |
.async(worker, ...) ⇒ Object
Permanently or temporarily inline callback workers. If no workers are given, it will inline all callback workers during the execution of the block or globally if no block is given. If a block and workers are given, workers provided will only be async during the execution of the block.
142 143 144 |
# File 'app/workers/sidekiq/callbacks.rb', line 142 def async(*workers, &block) set_workers(workers, :async, &block) end |
.disable(worker, ...) ⇒ Object
Permanently or temporarily disable callback workers. If no workers are given, it will disable all callback workers during the execution of the block or globally if no block is given. If a block and workers are given, workers provided will only be disabled during the execution of the block.
74 75 76 |
# File 'app/workers/sidekiq/callbacks.rb', line 74 def disable(*workers, &block) set_workers(workers, :disable, &block) end |
.enable(worker, ...) ⇒ Object
Permanently or temporarily enable callback workers. If no workers are given, it will enable all callback workers during the execution of the block or globally if no block is given. If a block and workers are given, workers provided will only be enable during the execution of the block. Callback workers already enabled will continue to be enabled during block execution.
41 42 43 |
# File 'app/workers/sidekiq/callbacks.rb', line 41 def enable(*workers, &block) set_workers(workers, :enable, &block) end |
.inline(worker, ...) ⇒ Object
Permanently or temporarily inline callback workers. If no workers are given, it will inline all callback workers during the execution of the block or globally if no block is given. If a block and workers are given, workers provided will only be inline during the execution of the block. Callback workers already inlined will continue to be inlined during block execution.
109 110 111 |
# File 'app/workers/sidekiq/callbacks.rb', line 109 def inline(*workers, &block) set_workers(workers, :inline, &block) end |
Instance Method Details
#run_callbacks(kind) ⇒ Object
191 192 193 194 195 |
# File 'app/workers/sidekiq/callbacks.rb', line 191 def run_callbacks(kind, *) result = super _enqueue_callback_workers(kind) if result != false && kind != :find result end |