Class: RocketJob::Worker
- Inherits:
-
Object
- Object
- RocketJob::Worker
- Extended by:
- Forwardable
- Includes:
- ActiveSupport::Callbacks, SemanticLogger::Loggable
- Defined in:
- lib/rocket_job/worker.rb
Overview
Worker
A worker runs on a single operating system thread Is usually started under a RocketJob server process.
Instance Attribute Summary collapse
-
#current_filter ⇒ Object
Returns the value of attribute current_filter.
-
#filter ⇒ Object
Returns the value of attribute filter.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#re_check_seconds ⇒ Object
Returns the value of attribute re_check_seconds.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Class Method Summary collapse
- .after_running(*filters, &blk) ⇒ Object
- .around_running(*filters, &blk) ⇒ Object
- .before_running(*filters, &blk) ⇒ Object
Instance Method Summary collapse
-
#initialize(id: 0, server_name: 'inline:0', inline: false, re_check_seconds: Config.instance.re_check_seconds, filter: nil) ⇒ Worker
constructor
A new instance of Worker.
-
#shutdown! ⇒ Object
Tells this worker to shutdown as soon the current job/slice is complete.
- #shutdown? ⇒ Boolean
Constructor Details
#initialize(id: 0, server_name: 'inline:0', inline: false, re_check_seconds: Config.instance.re_check_seconds, filter: nil) ⇒ Worker
Returns a new instance of Worker.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rocket_job/worker.rb', line 34 def initialize(id: 0, server_name: 'inline:0', inline: false, re_check_seconds: Config.instance.re_check_seconds, filter: nil) @id = id @server_name = server_name if defined?(Concurrent::JavaAtomicBoolean) || defined?(Concurrent::CAtomicBoolean) @shutdown = Concurrent::AtomicBoolean.new(false) else @shutdown = false end @name = "#{server_name}:#{id}" @re_check_seconds = (re_check_seconds || 60).to_f @re_check_start = Time.now @filter = filter || {} @current_filter = @filter.dup @thread = Thread.new { run } unless inline end |
Instance Attribute Details
#current_filter ⇒ Object
Returns the value of attribute current_filter.
19 20 21 |
# File 'lib/rocket_job/worker.rb', line 19 def current_filter @current_filter end |
#filter ⇒ Object
Returns the value of attribute filter.
19 20 21 |
# File 'lib/rocket_job/worker.rb', line 19 def filter @filter end |
#id ⇒ Object
Returns the value of attribute id.
19 20 21 |
# File 'lib/rocket_job/worker.rb', line 19 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
20 21 22 |
# File 'lib/rocket_job/worker.rb', line 20 def name @name end |
#re_check_seconds ⇒ Object
Returns the value of attribute re_check_seconds.
19 20 21 |
# File 'lib/rocket_job/worker.rb', line 19 def re_check_seconds @re_check_seconds end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
20 21 22 |
# File 'lib/rocket_job/worker.rb', line 20 def thread @thread end |
Class Method Details
.after_running(*filters, &blk) ⇒ Object
26 27 28 |
# File 'lib/rocket_job/worker.rb', line 26 def self.after_running(*filters, &blk) set_callback(:running, :after, *filters, &blk) end |
.around_running(*filters, &blk) ⇒ Object
30 31 32 |
# File 'lib/rocket_job/worker.rb', line 30 def self.around_running(*filters, &blk) set_callback(:running, :around, *filters, &blk) end |
.before_running(*filters, &blk) ⇒ Object
22 23 24 |
# File 'lib/rocket_job/worker.rb', line 22 def self.before_running(*filters, &blk) set_callback(:running, :before, *filters, &blk) end |
Instance Method Details
#shutdown! ⇒ Object
Tells this worker to shutdown as soon the current job/slice is complete
52 53 54 |
# File 'lib/rocket_job/worker.rb', line 52 def shutdown! @shutdown.make_true end |
#shutdown? ⇒ Boolean
56 57 58 |
# File 'lib/rocket_job/worker.rb', line 56 def shutdown? @shutdown.value end |