Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/foreman_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,25 @@ def self.delay(action, delay_options, *args)
ForemanTasks::Task::DynflowTask.where(:external_id => result.id).first!
end

# Chain a task to wait for prerequisite task(s) to finish before executing.
# The chained task remains 'scheduled' until all prerequisites reach 'stopped' state.
#
# @param plan_uuids [String, Array<String>] UUID(s) of prerequisite execution plan(s)
# @param action [Class] Action class to execute
# @param args Arguments to pass to the action
# @return [ForemanTasks::Task::DynflowTask] The chained task
def self.chain(plan_uuids, action, *args)
result = dynflow.world.chain(plan_uuids, action, *args)
ForemanTasks::Task.find_by(:external_id => result.id) ||
begin
delayed_plan = dynflow.world.persistence.load_delayed_plan(result.id)
execution_plan = dynflow.world.persistence.load_execution_plan(result.id)
ForemanTasks::Task::DynflowTask.new_for_execution_plan(execution_plan).tap do |task|
task.update_from_dynflow(execution_plan, delayed_plan)
end
end
Comment on lines +75 to +81
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really necessary? Chaining is "just" a special case of delay, for which we don't do this

Copy link
Contributor Author

@ianballou ianballou Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I needed this for it to be visible as a scheduled task in the ForemanTasks browser, but I can revisit that.
Eh, scratch that. I can probably remove this. Let me just double check that there wasn't a corner case why we needed to update the task, I can't remember now.

end

def self.register_scheduled_task(task_class, cronline)
ForemanTasks::RecurringLogic.transaction(isolation: :serializable) do
return if ForemanTasks::RecurringLogic.joins(:tasks)
Expand Down