Class: Whoosh::Jobs::Worker
- Inherits:
-
Object
- Object
- Whoosh::Jobs::Worker
- Defined in:
- lib/whoosh/jobs/worker.rb
Instance Method Summary collapse
-
#initialize(backend:, di: nil, max_retries: 3, retry_delay: 5, instrumentation: nil, logger: nil) ⇒ Worker
constructor
A new instance of Worker.
- #run_loop ⇒ Object
- #run_once(timeout: 5) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(backend:, di: nil, max_retries: 3, retry_delay: 5, instrumentation: nil, logger: nil) ⇒ Worker
Returns a new instance of Worker.
6 7 8 9 10 11 12 13 14 |
# File 'lib/whoosh/jobs/worker.rb', line 6 def initialize(backend:, di: nil, max_retries: 3, retry_delay: 5, instrumentation: nil, logger: nil) @backend = backend @di = di @max_retries = max_retries @retry_delay = retry_delay @instrumentation = instrumentation @logger = logger @running = true end |
Instance Method Details
#run_loop ⇒ Object
22 23 24 25 26 |
# File 'lib/whoosh/jobs/worker.rb', line 22 def run_loop while @running run_once end end |
#run_once(timeout: 5) ⇒ Object
16 17 18 19 20 |
# File 'lib/whoosh/jobs/worker.rb', line 16 def run_once(timeout: 5) job_data = @backend.pop(timeout: timeout) return unless job_data execute(job_data) end |
#stop ⇒ Object
28 29 30 |
# File 'lib/whoosh/jobs/worker.rb', line 28 def stop @running = false end |