Class: Tasker::Orchestration::ViableStepDiscovery

Inherits:
Object
  • Object
show all
Includes:
Concerns::EventPublisher
Defined in:
lib/tasker/orchestration/viable_step_discovery.rb

Overview

ViableStepDiscovery provides implementation for finding steps ready for execution

This class is a simple implementation provider that wraps the existing WorkflowStep.get_viable_steps logic while firing lifecycle events for observability. No complex event subscriptions needed.

Instance Method Summary collapse

Methods included from Concerns::EventPublisher

#infer_step_event_type_from_state, #publish_custom_event, #publish_no_viable_steps, #publish_step_backoff, #publish_step_before_handle, #publish_step_cancelled, #publish_step_completed, #publish_step_event_for_context, #publish_step_failed, #publish_step_retry_requested, #publish_step_started, #publish_steps_execution_completed, #publish_steps_execution_started, #publish_task_completed, #publish_task_enqueue, #publish_task_failed, #publish_task_finalization_completed, #publish_task_finalization_started, #publish_task_pending_transition, #publish_task_reenqueue_delayed, #publish_task_reenqueue_failed, #publish_task_reenqueue_requested, #publish_task_reenqueue_started, #publish_task_retry_requested, #publish_task_started, #publish_viable_steps_discovered, #publish_workflow_state_unclear, #publish_workflow_step_completed, #publish_workflow_task_started

Instance Method Details

#discover_steps_for_task(task_id) ⇒ Array<Tasker::WorkflowStep>

Discover viable steps for a task by task ID

Convenience method for testing and external usage that loads a task and gets its sequence before calling find_viable_steps.

Parameters:

  • task_id (String)

    The task ID to discover steps for

Returns:



57
58
59
60
61
62
# File 'lib/tasker/orchestration/viable_step_discovery.rb', line 57

def discover_steps_for_task(task_id)
  task = Tasker::Task.find(task_id)
  task_handler = Tasker::HandlerFactory.instance.get(task.name)
  sequence = Tasker::Orchestration::StepSequenceFactory.get_sequence(task, task_handler)
  find_viable_steps(task, sequence)
end

#find_viable_steps(task, sequence) ⇒ Array<Tasker::WorkflowStep>

Find viable steps for execution

This is just a clean wrapper around the existing WorkflowStep.get_viable_steps method that fires observability events.

Parameters:

Returns:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/tasker/orchestration/viable_step_discovery.rb', line 25

def find_viable_steps(task, sequence)
  # Use the existing proven logic - this is where the real work happens
  viable_steps = Tasker::WorkflowStep.get_viable_steps(task, sequence)

  # Fire appropriate discovery event based on results through orchestrator
  if viable_steps.any?
    publish_viable_steps_discovered(
      task.task_id,
      viable_steps.map(&:workflow_step_id),
      processing_mode: 'concurrent',
      viable_count: viable_steps.size,
      step_names: viable_steps.map(&:name)
    )
  else
    publish_no_viable_steps(
      task.task_id,
      reason: 'No steps ready for execution',
      total_steps_checked: sequence.steps.size
    )
  end

  Rails.logger.debug { "ViableStepDiscovery: Found #{viable_steps.size} viable steps for task #{task.task_id}" }
  viable_steps
end