Module: Tasker::TaskHandler::InstanceMethods

Includes:
Concerns::EventPublisher
Defined in:
lib/tasker/task_handler/instance_methods.rb

Overview

Instance methods for task handlers

Provides the core task processing logic including the main execution loop, step handling, and finalization. Delegates to orchestration components for implementation details while maintaining proven loop-based approach.

Author:

  • TaskHandler Authors

Constant Summary collapse

TASK_REQUEST_ATTRIBUTES =

List of attributes to pass from the task request to the task

These are the attributes that will be copied from the task request to the task when initializing a new task.

Returns:

  • (Array<Symbol>)

    List of attribute names

%i[name context initiator reason source_system].freeze

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

#dependency_graphHash

Get dependency graph analysis for this task handler's step templates

Provides comprehensive analysis of step dependencies, including cycle detection, topological ordering, and dependency visualization. Useful for troubleshooting and understanding workflow structure.

Returns:

  • (Hash)

    Comprehensive dependency analysis containing:

    • :nodes - Array of step information with dependencies
    • :edges - Array of dependency relationships
    • :topology - Topologically sorted step names
    • :cycles - Array of detected circular dependencies
    • :levels - Hash mapping steps to their dependency depth levels
    • :roots - Array of steps with no dependencies
    • :leaves - Array of steps with no dependents


148
149
150
# File 'lib/tasker/task_handler/instance_methods.rb', line 148

def dependency_graph
  template_analyzer.analyze
end

#establish_step_dependencies_and_defaults(task, steps) ⇒ void

This method returns an undefined value.

Establish step dependencies and defaults

This is a hook method that can be overridden by implementing classes. This method is public so that orchestration components can call it.

Parameters:



90
# File 'lib/tasker/task_handler/instance_methods.rb', line 90

def establish_step_dependencies_and_defaults(task, steps); end

#get_sequence(task) ⇒ Tasker::Types::StepSequence

Get the step sequence for a task

Retrieves all workflow steps for the task and establishes their dependencies. Delegates to StepSequenceFactory for implementation + observability events.

Parameters:

Returns:



50
51
52
53
# File 'lib/tasker/task_handler/instance_methods.rb', line 50

def get_sequence(task)
  # Delegate to orchestration system for implementation + events
  Tasker::Orchestration::StepSequenceFactory.get_sequence(task, self)
end

#get_step_handler(step) ⇒ Object

Get a step handler for a specific step

This method is public so that orchestration components can access step handlers.

Parameters:

Returns:

  • (Object)

    The step handler

Raises:



110
111
112
113
114
115
116
117
118
119
# File 'lib/tasker/task_handler/instance_methods.rb', line 110

def get_step_handler(step)
  raise(Tasker::ProceduralError, "No registered class for #{step.name}") unless step_handler_class_map[step.name]

  handler_config = step_handler_config_map[step.name]
  handler_class = step_handler_class_map[step.name].to_s.camelize.constantize

  return handler_class.new if handler_config.nil?

  handler_class.new(config: handler_config)
end

#handle(task) ⇒ void

This method returns an undefined value.

Handle a task's execution

This is the main entry point for processing a task. Delegates to WorkflowCoordinator for the execution loop to enable strategy composition.

Parameters:



74
75
76
77
78
79
80
# File 'lib/tasker/task_handler/instance_methods.rb', line 74

def handle(task)
  start_task(task)

  # DELEGATE: Use WorkflowCoordinator for execution loop
  # This enables strategy pattern composition for testing
  workflow_coordinator.execute_workflow(task, self)
end

#handle_one_step(task, sequence, step) ⇒ Tasker::WorkflowStep

Handle execution of a single step

This is a convenience method for testing that executes a single step. Delegates to StepExecutor for consistent behavior.

Parameters:

Returns:



130
131
132
# File 'lib/tasker/task_handler/instance_methods.rb', line 130

def handle_one_step(task, sequence, step)
  step_executor.execute_single_step(task, sequence, step, self)
end

#initialize_task!(task_request) ⇒ Tasker::Task

Initialize a task

Validates input and creates initial workflow steps via orchestration.

Parameters:

  • task_request (TaskRequest)

    The task request to initialize

Returns:



38
39
40
41
# File 'lib/tasker/task_handler/instance_methods.rb', line 38

def initialize_task!(task_request)
  # Delegate to orchestration system
  Tasker::Orchestration::TaskInitializer.initialize_task!(task_request, self)
end

#reenqueuer_strategy=(strategy) ⇒ Object

Set the reenqueuer strategy (for testing)

Parameters:

  • strategy (Class)

    The reenqueuer strategy class



202
203
204
205
# File 'lib/tasker/task_handler/instance_methods.rb', line 202

def reenqueuer_strategy=(strategy)
  @reenqueuer_strategy = strategy
  @workflow_coordinator = nil # Reset memoized instance
end

#start_task(task) ⇒ Boolean

Start a task's execution

Updates the task status to IN_PROGRESS and fires the appropriate event.

Parameters:

Returns:

  • (Boolean)

    True if the task was started successfully

Raises:



62
63
64
65
# File 'lib/tasker/task_handler/instance_methods.rb', line 62

def start_task(task)
  # Delegate to orchestration system
  Tasker::Orchestration::TaskInitializer.start_task!(task)
end

#update_annotations(task, sequence, steps) ⇒ void

This method returns an undefined value.

Update annotations based on processed steps

This is a hook method that can be overridden by implementing classes. This method is public so that orchestration components can call it.

Parameters:



101
# File 'lib/tasker/task_handler/instance_methods.rb', line 101

def update_annotations(task, sequence, steps); end

#workflow_coordinator_strategy=(strategy) ⇒ Object

Set the workflow coordinator strategy (for testing)

Parameters:

  • strategy (Class)

    The workflow coordinator strategy class



194
195
196
197
# File 'lib/tasker/task_handler/instance_methods.rb', line 194

def workflow_coordinator_strategy=(strategy)
  @workflow_coordinator_strategy = strategy
  @workflow_coordinator = nil # Reset memoized instance
end