Module: Actions::Helpers::LifecycleLogging

Included in:
Base
Defined in:
app/lib/actions/helpers/lifecycle_logging.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'app/lib/actions/helpers/lifecycle_logging.rb', line 4

def self.included(base)
  base.execution_plan_hooks.use :log_task_state_change
end

Instance Method Details

#log_task_state_change(execution_plan) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'app/lib/actions/helpers/lifecycle_logging.rb', line 8

def log_task_state_change(execution_plan)
  return unless root_action?
  logger = ::Rails.application.dynflow.world.action_logger
  task_id = ForemanTasks::Task::DynflowTask.where(external_id: execution_plan.id).pluck(:id).first

  task_id_parts = []
  task_id_parts << "id: #{task_id}" if task_id
  task_id_parts << "execution_plan_id: #{execution_plan.id}"
  result_info = " result: #{execution_plan.result}" if [:stopped, :paused].include?(execution_plan.state)
  logger.info("Task {label: #{execution_plan.label}, #{task_id_parts.join(', ')}} state changed: #{execution_plan.state} #{result_info}")
end