Class: Relay::Task
- Inherits:
-
Object
- Object
- Relay::Task
- Defined in:
- lib/relay/task.rb
Overview
Task represents a Rake task that can be run in a separate process. The process becomes a group leader, so that if it spawns any child processes, they will be in the same process group.
A task provides its status through a channel, which can be either “success” or “error” depending on whether the task completed successfully or not.
Instance Attribute Summary collapse
- #ch ⇒ Chan::UNIXSocket readonly
- #pid ⇒ Integer readonly
Instance Method Summary collapse
-
#call ⇒ Integer
Call the task in a separate process.
- #initialize(task) ⇒ void constructor
-
#status ⇒ String
Read the status of a task (non-blocking).
Constructor Details
#initialize(task) ⇒ void
27 28 29 30 31 |
# File 'lib/relay/task.rb', line 27 def initialize(task) @task = task @ch = xchan(:pure) @pid = nil end |
Instance Attribute Details
#ch ⇒ Chan::UNIXSocket (readonly)
17 18 19 |
# File 'lib/relay/task.rb', line 17 def ch @ch end |
#pid ⇒ Integer (readonly)
21 22 23 |
# File 'lib/relay/task.rb', line 21 def pid @pid end |
Instance Method Details
#call ⇒ Integer
Call the task in a separate process
37 38 39 40 41 42 43 44 45 |
# File 'lib/relay/task.rb', line 37 def call @pid = fork do become_group_leader invoke_task record_success rescue record_error end end |
#status ⇒ String
Read the status of a task (non-blocking)
53 54 55 56 |
# File 'lib/relay/task.rb', line 53 def status return @status if defined?(@status) @status = ch.recv_nonblock end |