Module: Tasker::StateMachine

Defined in:
lib/tasker.rb,
lib/tasker/state_machine.rb,
lib/tasker/state_machine/step_state_machine.rb,
lib/tasker/state_machine/task_state_machine.rb

Overview

StateMachine module provides declarative state management for tasks and steps

This module integrates Statesman-based state machines with the existing Tasker lifecycle events system to provide a unified, event-driven approach to workflow state management.

Defined Under Namespace

Modules: Compatibility Classes: InvalidStateTransition, StepStateMachine, TaskStateMachine

Class Method Summary collapse

Class Method Details

.configure_statesmanvoid

This method returns an undefined value.

Configure Statesman for Tasker



40
41
42
43
44
# File 'lib/tasker/state_machine.rb', line 40

def configure_statesman
  # Statesman doesn't require global configuration
  # State machines use ActiveRecord adapters through transition models
  true
end

.configured?Boolean

Check if state machines are properly configured

Returns:

  • (Boolean)

    True if configuration is valid



65
66
67
68
69
# File 'lib/tasker/state_machine.rb', line 65

def configured?
  !!(defined?(Statesman) &&
     TaskStateMachine.respond_to?(:new) &&
     StepStateMachine.respond_to?(:new))
end

.initialize_step_state_machine(step) ⇒ StepStateMachine

Initialize state machines for a step

Parameters:

Returns:



58
59
60
# File 'lib/tasker/state_machine.rb', line 58

def initialize_step_state_machine(step)
  StepStateMachine.new(step)
end

.initialize_task_state_machine(task) ⇒ TaskStateMachine

Initialize state machines for a task

Parameters:

  • task (Task)

    The task to initialize

Returns:



50
51
52
# File 'lib/tasker/state_machine.rb', line 50

def initialize_task_state_machine(task)
  TaskStateMachine.new(task)
end

.statisticsHash

Get statistics about state machine usage

Returns:

  • (Hash)

    Statistics hash



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

def statistics
  {
    task_states: Constants::VALID_TASK_STATUSES,
    step_states: Constants::VALID_WORKFLOW_STEP_STATUSES,
    configured: configured?
  }
end