Class: Jiggler::Worker
- Inherits:
-
Object
- Object
- Jiggler::Worker
- Includes:
- Support::Helper
- Defined in:
- lib/jiggler/worker.rb
Defined Under Namespace
Classes: CurrentJob
Instance Attribute Summary collapse
-
#acknowledger ⇒ Object
readonly
Returns the value of attribute acknowledger.
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#current_job ⇒ Object
readonly
Returns the value of attribute current_job.
-
#fetcher ⇒ Object
readonly
Returns the value of attribute fetcher.
Instance Method Summary collapse
-
#initialize(config, collection, acknowledger, fetcher, &callback) ⇒ Worker
constructor
A new instance of Worker.
- #run ⇒ Object
- #terminate ⇒ Object
- #wait ⇒ Object
Methods included from Support::Helper
#log_error, #log_error_short, #logger, #safe_async, #scan_all, #tid
Constructor Details
#initialize(config, collection, acknowledger, fetcher, &callback) ⇒ Worker
Returns a new instance of Worker.
11 12 13 14 15 16 17 18 19 |
# File 'lib/jiggler/worker.rb', line 11 def initialize(config, collection, acknowledger, fetcher, &callback) @done = false @current_job = nil @callback = callback @config = config @collection = collection @acknowledger = acknowledger @fetcher = fetcher end |
Instance Attribute Details
#acknowledger ⇒ Object (readonly)
Returns the value of attribute acknowledger.
9 10 11 |
# File 'lib/jiggler/worker.rb', line 9 def acknowledger @acknowledger end |
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
9 10 11 |
# File 'lib/jiggler/worker.rb', line 9 def collection @collection end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/jiggler/worker.rb', line 9 def config @config end |
#current_job ⇒ Object (readonly)
Returns the value of attribute current_job.
9 10 11 |
# File 'lib/jiggler/worker.rb', line 9 def current_job @current_job end |
#fetcher ⇒ Object (readonly)
Returns the value of attribute fetcher.
9 10 11 |
# File 'lib/jiggler/worker.rb', line 9 def fetcher @fetcher end |
Instance Method Details
#run ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/jiggler/worker.rb', line 21 def run reason = nil @runner = safe_async('Worker') do @tid = tid loop do if @done @runner = nil break @callback.call(self) end process_job # pass control to other fibers Async::Task.current.yield rescue Async::Stop @runner = nil break @callback.call(self) rescue => err collection.incr_failures @runner = nil break @callback.call(self, err) end end end |
#terminate ⇒ Object
46 47 48 |
# File 'lib/jiggler/worker.rb', line 46 def terminate @runner&.stop end |
#wait ⇒ Object
50 51 52 |
# File 'lib/jiggler/worker.rb', line 50 def wait @runner&.wait end |