Class: Tasker::Functions::FunctionBasedTaskExecutionContext

Inherits:
FunctionWrapper
  • Object
show all
Defined in:
lib/tasker/functions/function_based_task_execution_context.rb

Overview

Function-based implementation of TaskExecutionContext Maintains the same interface as the view-based model but uses SQL functions for performance

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FunctionWrapper

connection, convert_array_bind, from_sql_function, #readonly?, single_from_sql_function

Class Method Details

.find(task_id) ⇒ Object

Class methods that use SQL functions



26
27
28
29
30
# File 'lib/tasker/functions/function_based_task_execution_context.rb', line 26

def self.find(task_id)
  sql = 'SELECT * FROM get_task_execution_context($1::BIGINT)'
  binds = [task_id]
  single_from_sql_function(sql, binds, 'TaskExecutionContext Load')
end

.for_tasks(task_ids) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/tasker/functions/function_based_task_execution_context.rb', line 32

def self.for_tasks(task_ids)
  return [] if task_ids.empty?

  # Use the batch function to avoid N+1 queries
  sql = 'SELECT * FROM get_task_execution_contexts_batch($1::BIGINT[])'
  binds = [task_ids]
  from_sql_function(sql, binds, 'TaskExecutionContext Batch Load')
end

Instance Method Details

#can_make_progress?Boolean



63
64
65
# File 'lib/tasker/functions/function_based_task_execution_context.rb', line 63

def can_make_progress?
  ready_steps.positive?
end

#has_work_to_do?Boolean

Helper methods for workflow decision making (same as original model)



42
43
44
45
# File 'lib/tasker/functions/function_based_task_execution_context.rb', line 42

def has_work_to_do?
  Constants::ACTIONABLE_TASK_EXECUTION_STATUSES.include?(execution_status) ||
    execution_status == Constants::TaskExecution::ExecutionStatus::PROCESSING
end

#is_blocked?Boolean



47
48
49
# File 'lib/tasker/functions/function_based_task_execution_context.rb', line 47

def is_blocked?
  execution_status == Constants::TaskExecution::ExecutionStatus::BLOCKED_BY_FAILURES
end

#is_complete?Boolean



51
52
53
# File 'lib/tasker/functions/function_based_task_execution_context.rb', line 51

def is_complete?
  execution_status == Constants::TaskExecution::ExecutionStatus::ALL_COMPLETE
end

#is_healthy?Boolean



55
56
57
# File 'lib/tasker/functions/function_based_task_execution_context.rb', line 55

def is_healthy?
  health_status == Constants::TaskExecution::HealthStatus::HEALTHY
end

#needs_immediate_action?Boolean



71
72
73
# File 'lib/tasker/functions/function_based_task_execution_context.rb', line 71

def needs_immediate_action?
  Constants::ACTIONABLE_TASK_EXECUTION_STATUSES.include?(execution_status)
end

#needs_intervention?Boolean



59
60
61
# File 'lib/tasker/functions/function_based_task_execution_context.rb', line 59

def needs_intervention?
  health_status == Constants::TaskExecution::HealthStatus::BLOCKED
end

#next_action_detailsObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/tasker/functions/function_based_task_execution_context.rb', line 102

def next_action_details
  case recommended_action
  when Constants::TaskExecution::RecommendedAction::EXECUTE_READY_STEPS
    {
      action: Constants::TaskExecution::RecommendedAction::EXECUTE_READY_STEPS,
      description: "#{ready_steps} steps ready for execution",
      urgency: 'high',
      can_proceed: true
    }
  when Constants::TaskExecution::RecommendedAction::WAIT_FOR_COMPLETION
    {
      action: Constants::TaskExecution::RecommendedAction::WAIT_FOR_COMPLETION,
      description: "#{in_progress_steps} steps currently processing",
      urgency: 'low',
      can_proceed: false
    }
  when Constants::TaskExecution::RecommendedAction::HANDLE_FAILURES
    {
      action: Constants::TaskExecution::RecommendedAction::HANDLE_FAILURES,
      description: "#{failed_steps} failed steps blocking progress",
      urgency: 'critical',
      can_proceed: false
    }
  when Constants::TaskExecution::RecommendedAction::FINALIZE_TASK
    {
      action: Constants::TaskExecution::RecommendedAction::FINALIZE_TASK,
      description: 'All steps completed successfully',
      urgency: 'medium',
      can_proceed: true
    }
  else
    {
      action: Constants::TaskExecution::RecommendedAction::WAIT_FOR_DEPENDENCIES,
      description: 'Waiting for dependencies to be satisfied',
      urgency: 'low',
      can_proceed: false
    }
  end
end

#progress_detailsObject



92
93
94
95
96
97
98
99
100
# File 'lib/tasker/functions/function_based_task_execution_context.rb', line 92

def progress_details
  {
    completed_ratio: "#{completed_steps}/#{total_steps}",
    completion_percentage: "#{completion_percentage}%",
    remaining_steps: total_steps - completed_steps,
    failed_steps: failed_steps,
    ready_steps: ready_steps
  }
end

#should_reenqueue?Boolean



67
68
69
# File 'lib/tasker/functions/function_based_task_execution_context.rb', line 67

def should_reenqueue?
  Constants::REENQUEUE_TASK_EXECUTION_STATUSES.include?(execution_status)
end

#taskObject

Association (lazy-loaded)



143
144
145
# File 'lib/tasker/functions/function_based_task_execution_context.rb', line 143

def task
  @task ||= Tasker::Task.find(task_id)
end

#workflow_summaryObject

Status summary methods (same as original model)



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/tasker/functions/function_based_task_execution_context.rb', line 76

def workflow_summary
  {
    total_steps: total_steps,
    completed: completed_steps,
    pending: pending_steps,
    in_progress: in_progress_steps,
    failed: failed_steps,
    ready: ready_steps,
    completion_percentage: completion_percentage,
    status: execution_status,
    health: health_status,
    recommended_action: recommended_action,
    progress_details: progress_details
  }
end