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.
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.
%i[name context initiator reason source_system].freeze
Instance Method Summary collapse
-
#dependency_graph ⇒ Hash
Get dependency graph analysis for this task handler's step templates.
-
#establish_step_dependencies_and_defaults(task, steps) ⇒ void
Establish step dependencies and defaults.
-
#get_sequence(task) ⇒ Tasker::Types::StepSequence
Get the step sequence for a task.
-
#get_step_handler(step) ⇒ Object
Get a step handler for a specific step.
-
#handle(task) ⇒ void
Handle a task's execution.
-
#handle_one_step(task, sequence, step) ⇒ Tasker::WorkflowStep
Handle execution of a single step.
-
#initialize_task!(task_request) ⇒ Tasker::Task
Initialize a task.
-
#reenqueuer_strategy=(strategy) ⇒ Object
Set the reenqueuer strategy (for testing).
-
#start_task(task) ⇒ Boolean
Start a task's execution.
-
#update_annotations(task, sequence, steps) ⇒ void
Update annotations based on processed steps.
-
#workflow_coordinator_strategy=(strategy) ⇒ Object
Set the workflow coordinator strategy (for testing).
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_graph ⇒ Hash
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.
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.
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.
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.
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.
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.
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.
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)
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.
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.
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)
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 |