From 98832ba6aa66b1caf3d3f8aba353214de1731e36 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Thu, 21 Sep 2023 12:33:40 -0400 Subject: [PATCH 1/2] Run workflows on MiqAutomationWorker asynchronously Rather than running each step in a single queue message synchronously, execute WorkflowInstances asynchronously and requeue once the workflow would block. --- .../workflows/automation_manager/workflow_instance.rb | 9 ++++++--- .../automation_manager/workflow_instance_spec.rb | 7 ++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/models/manageiq/providers/workflows/automation_manager/workflow_instance.rb b/app/models/manageiq/providers/workflows/automation_manager/workflow_instance.rb index bc3b47d..cf91c19 100644 --- a/app/models/manageiq/providers/workflows/automation_manager/workflow_instance.rb +++ b/app/models/manageiq/providers/workflows/automation_manager/workflow_instance.rb @@ -1,5 +1,5 @@ class ManageIQ::Providers::Workflows::AutomationManager::WorkflowInstance < ManageIQ::Providers::EmbeddedAutomationManager::ConfigurationScript - def run_queue(zone: nil, role: "automate", object: nil) + def run_queue(zone: nil, role: "automate", object: nil, deliver_on: nil, server_guid: nil) raise _("run_queue is not enabled") unless Settings.prototype.ems_workflows.enabled args = {:zone => zone, :role => role} @@ -12,9 +12,12 @@ def run_queue(zone: nil, role: "automate", object: nil) :class_name => self.class.name, :instance_id => id, :method_name => "run", + :queue_name => "automate", :role => role, :zone => zone, :args => [args], + :deliver_on => deliver_on, + :server_guid => server_guid } if miq_task_id @@ -69,7 +72,7 @@ def run(args = {}) end wf = Floe::Workflow.new(payload, context, creds) - wf.step + wf.run_nonblock update!(:context => wf.context.to_h, :status => wf.status, :output => wf.output) @@ -87,6 +90,6 @@ def run(args = {}) object.after_ae_delivery(ae_result) end - run_queue(:zone => zone, :role => role, :object => object) unless wf.end? + run_queue(:zone => zone, :role => role, :object => object, :deliver_on => 10.seconds.from_now.utc, :server_guid => MiqServer.my_server.guid) unless wf.end? end end diff --git a/spec/models/manageiq/providers/workflows/automation_manager/workflow_instance_spec.rb b/spec/models/manageiq/providers/workflows/automation_manager/workflow_instance_spec.rb index 72d271b..efebd35 100644 --- a/spec/models/manageiq/providers/workflows/automation_manager/workflow_instance_spec.rb +++ b/spec/models/manageiq/providers/workflows/automation_manager/workflow_instance_spec.rb @@ -96,15 +96,16 @@ end context "with a zone and role" do - let(:zone) { FactoryBot.create(:zone) } + let(:zone) { EvmSpecHelper.local_miq_server.zone } let(:payload) do { "Comment" => "Example Workflow", "StartAt" => "FirstState", "States" => { "FirstState" => { - "Type" => "Pass", - "Next" => "SuccessState" + "Type" => "Wait", + "Seconds" => 10, + "Next" => "SuccessState" }, "SuccessState" => { "Type" => "Succeed" From 2d1adb93ae68374e0964cb2e672f499c37e780a9 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Tue, 26 Sep 2023 16:46:20 -0400 Subject: [PATCH 2/2] Bump floe to v0.4.0 for step_nonblock --- manageiq-providers-workflows.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manageiq-providers-workflows.gemspec b/manageiq-providers-workflows.gemspec index d36a2d8..6d858e0 100644 --- a/manageiq-providers-workflows.gemspec +++ b/manageiq-providers-workflows.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_dependency "floe", "~> 0.3.0" + spec.add_dependency "floe", "~> 0.4.0" spec.add_development_dependency "manageiq-style" spec.add_development_dependency "simplecov", ">= 0.21.2"