From 0d1e031d66c96dcd4e55dac39782d73bbd989926 Mon Sep 17 00:00:00 2001 From: Jason Frey Date: Wed, 27 Sep 2023 11:16:50 -0400 Subject: [PATCH] Merge pull request #50 from agrare/run_workflows_on_miq_automation_worker Run workflows asyncrhonously on MiqAutomationWorker (cherry picked from commit be6f4d1e202f6ea61510a3488281ba62452e5f25) --- .../workflows/automation_manager/workflow_instance.rb | 9 ++++++--- manageiq-providers-workflows.gemspec | 2 +- .../automation_manager/workflow_instance_spec.rb | 7 ++++--- 3 files changed, 11 insertions(+), 7 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/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" 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"