ManageIQ / floe

Floe is a runner for Amazon States Language workflows
Apache License 2.0
0 stars 5 forks source link

Set StateHistory in Workflow not State #211

Closed agrare closed 2 months ago

agrare commented 2 months ago

NOTE I moved step_next after the run, since we have a dedicated start_workflow which sets the initial state context we no longer need step_next to pull double-duty here

kbrock commented 2 months ago
diff --git a/lib/floe/workflow.rb b/lib/floe/workflow.rb
index 69b0709..26cb872 100644
--- a/lib/floe/workflow.rb
+++ b/lib/floe/workflow.rb
@@ -120,8 +120,10 @@ module Floe
       return Errno::EPERM if end?

       result = current_state.run_nonblock!
-      step_next
-      end_workflow
+      if context.state_finished?
+        step_next
+        end_workflow
+      end

       result
     end
diff --git a/spec/workflow/states/wait_spec.rb b/spec/workflow/states/wait_spec.rb
index 0a17a85..e907d3d 100644
--- a/spec/workflow/states/wait_spec.rb
+++ b/spec/workflow/states/wait_spec.rb
@@ -90,6 +90,19 @@ RSpec.describe Floe::Workflow::States::Pass do
         end
         expect(state.running?).to be_falsey
       end
+
+      it "runs" do
+        workflow.run_nonblock
+        expect(workflow.end?).to eq(false)
+        expect(workflow.context.state_history.size).to eq(0)
+
+        Timecop.travel(Time.now.utc + 10) do
+          workflow.run_nonblock
+        end
+
+        expect(workflow.end?).to eq(true)
+        expect(workflow.context.state_history.size).to eq(2)
+      end
     end
miq-bot commented 2 months ago

Checked commits https://github.com/agrare/floe/compare/46a68f45ead15fdf9990d91c264fcef826255068~...e07a41489790ccfb9e0f90df2913c05c92091378 with ruby 2.7.8, rubocop 1.56.3, haml-lint 0.51.0, and yamllint 4 files checked, 0 offenses detected Everything looks fine. :trophy: