Class: Shikibu::Worker
- Inherits:
-
Object
- Object
- Shikibu::Worker
- Defined in:
- lib/shikibu/worker.rb
Overview
Background worker for workflow processing
Constant Summary collapse
- WORKFLOW_POLL_INTERVAL =
1- TIMER_CHECK_INTERVAL =
10- STALE_LOCK_INTERVAL =
60- MESSAGE_CHECK_INTERVAL =
5- MESSAGE_CLEANUP_INTERVAL =
1 hour
3600- DEFAULT_MESSAGE_RETENTION_DAYS =
7
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#message_wake_event ⇒ Object
readonly
Returns the value of attribute message_wake_event.
-
#outbox_wake_event ⇒ Object
readonly
Returns the value of attribute outbox_wake_event.
-
#resume_wake_event ⇒ Object
readonly
Returns the value of attribute resume_wake_event.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
-
#worker_id ⇒ Object
readonly
Returns the value of attribute worker_id.
Instance Method Summary collapse
-
#initialize(app) ⇒ Worker
constructor
A new instance of Worker.
- #leader? ⇒ Boolean
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(app) ⇒ Worker
Returns a new instance of Worker.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/shikibu/worker.rb', line 15 def initialize(app) @app = app @storage = app.storage @worker_id = app.worker_id @running = false @threads = [] @is_leader = false @leader_tasks = [] # Wake events for NOTIFY integration @resume_wake_event = Notify::WakeEvent.new = Notify::WakeEvent.new @outbox_wake_event = Notify::WakeEvent.new end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
13 14 15 |
# File 'lib/shikibu/worker.rb', line 13 def app @app end |
#message_wake_event ⇒ Object (readonly)
Returns the value of attribute message_wake_event.
13 14 15 |
# File 'lib/shikibu/worker.rb', line 13 def end |
#outbox_wake_event ⇒ Object (readonly)
Returns the value of attribute outbox_wake_event.
13 14 15 |
# File 'lib/shikibu/worker.rb', line 13 def outbox_wake_event @outbox_wake_event end |
#resume_wake_event ⇒ Object (readonly)
Returns the value of attribute resume_wake_event.
13 14 15 |
# File 'lib/shikibu/worker.rb', line 13 def resume_wake_event @resume_wake_event end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
13 14 15 |
# File 'lib/shikibu/worker.rb', line 13 def storage @storage end |
#worker_id ⇒ Object (readonly)
Returns the value of attribute worker_id.
13 14 15 |
# File 'lib/shikibu/worker.rb', line 13 def worker_id @worker_id end |
Instance Method Details
#leader? ⇒ Boolean
54 55 56 |
# File 'lib/shikibu/worker.rb', line 54 def leader? @is_leader end |
#running? ⇒ Boolean
50 51 52 |
# File 'lib/shikibu/worker.rb', line 50 def running? @running end |
#start ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/shikibu/worker.rb', line 30 def start return if @running @running = true # All workers run these @threads << Thread.new { run_workflow_resumption } @threads << Thread.new { } # Leader election and leader-only tasks @threads << Thread.new { run_leader_election } end |
#stop ⇒ Object
43 44 45 46 47 48 |
# File 'lib/shikibu/worker.rb', line 43 def stop @running = false stop_leader_tasks @threads.each { |t| t.join(5) } @threads.clear end |