Class: Insika::Commands::PauseTask
- Inherits:
-
Object
- Object
- Insika::Commands::PauseTask
- Defined in:
- lib/insika/commands/pause_task.rb
Overview
Control command: posts :pause to the Task's in-process
mailbox and responds synchronously. Payload { task_id: String } -> returns Task.
Cooperative: the one that transitions running -> paused and emits
:task_paused is the task's fiber when it drains at the next boundary — NEVER this
handler. Pausing a task with no live fiber (terminal/orphaned) is an idempotent no-op.
Instance Method Summary collapse
- #call(command) ⇒ Object
-
#initialize(task_store:, executor:) ⇒ PauseTask
constructor
A new instance of PauseTask.
Constructor Details
#initialize(task_store:, executor:) ⇒ PauseTask
Returns a new instance of PauseTask.
12 13 14 15 |
# File 'lib/insika/commands/pause_task.rb', line 12 def initialize(task_store:, executor:) @task_store = task_store @executor = executor end |
Instance Method Details
#call(command) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/insika/commands/pause_task.rb', line 17 def call(command) task_id = command.payload[:task_id] || command.payload["task_id"] raise Insika::ValidationError, "task_id is required" if task_id.to_s.empty? task = @task_store.find(task_id) raise Insika::NotFoundError, "task '#{task_id}' not found" unless task @executor.pause(task_id) # no-op if there is no live fiber in this process @task_store.find(task_id) # current state after the post end |