Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set `State["PreviousStateGuid"] in StateHistory #208

Merged
merged 3 commits into from
Jun 14, 2024

Conversation

agrare
Copy link
Member

@agrare agrare commented Jun 6, 2024

Make the state history more obvious by including the exact previous state Guid in the StateHistory

[{"Name"=>"FirstState",
  "Input"=>{"foo"=>1},
  "Guid"=>"b0f264bb-663e-4b6a-9034-e79b9b9d0c5a",
  "EnteredTime"=>"2024-06-06T18:55:19Z",
  "Output"=>{"foo"=>1},
  "NextState"=>"ChoiceState",
  "FinishedTime"=>"2024-06-06T18:55:19Z",
  "Duration"=>0.416348275},
 {"Name"=>"ChoiceState",
  "PreviousStateGuid"=>"b0f264bb-663e-4b6a-9034-e79b9b9d0c5a",
  "Guid"=>"cf1d9b27-5453-4ef6-880e-3282ccb604d3",
  "Input"=>{"foo"=>1},
  "EnteredTime"=>"2024-06-06T18:55:19Z",
  "NextState"=>"FirstMatchState",
  "Output"=>{"foo"=>1},
  "FinishedTime"=>"2024-06-06T18:55:19Z",
  "Duration"=>0.487305373},
 {"Name"=>"FirstMatchState",
  "PreviousStateGuid"=>"cf1d9b27-5453-4ef6-880e-3282ccb604d3",
  "Guid"=>"6f9703ad-7ee2-43e1-b7f3-d4bd26c00055",
  "Input"=>{"foo"=>1},
  "EnteredTime"=>"2024-06-06T18:55:19Z",
  "Output"=>{"foo"=>1},
  "NextState"=>"PassState",
  "FinishedTime"=>"2024-06-06T18:55:19Z",
  "Duration"=>0.74080356}

@agrare agrare requested a review from Fryguy as a code owner June 6, 2024 19:01
@miq-bot miq-bot added the wip label Jun 6, 2024
lib/floe/workflow.rb Outdated Show resolved Hide resolved

return unless context.next_state

next_state = {"Name" => context.next_state, "PreviousStateGuid" => context.state["Guid"]}
Copy link
Member

Choose a reason for hiding this comment

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

Nice. Introducing next_state removes that restore_values which was a little confusing.

Copy link
Member

@kbrock kbrock Jun 12, 2024

Choose a reason for hiding this comment

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

Do you want to have Guid a Workflow concept?

diff --git a/lib/floe/workflow.rb b/lib/floe/workflow.rb
index c7d5b37..68ee848 100644
--- a/lib/floe/workflow.rb
+++ b/lib/floe/workflow.rb
@@ -167,2 +167,3 @@ module Floe
       context.state["Input"] = context.execution["Input"].dup
+      context.state["Guid"] = SecureRandom.uuid
       context.execution["StartTime"] = Time.now.utc.iso8601
@@ -180,3 +181,3 @@ module Floe
     def step!
-      next_state = {"Name" => context.next_state, "PreviousStateGuid" => context.state["Guid"]}
+      next_state = {"Name" => context.next_state, "Guid" => SecureRandom.uuid, "PreviousStateGuid" => context.state["Guid"]}

diff --git a/lib/floe/workflow/state.rb b/lib/floe/workflow/state.rb
index a44b584..c757f97 100644
--- a/lib/floe/workflow/state.rb
+++ b/lib/floe/workflow/state.rb
@@ -55,3 +55,2 @@ module Floe
       def start(_input)
-        context.state["Guid"]        = SecureRandom.uuid
         context.state["EnteredTime"] = Time.now.utc.iso8601

@kbrock
Copy link
Member

kbrock commented Jun 12, 2024

This will work great after #211
Or sneak into 211 - your choice.

@agrare agrare changed the title [WIP] Set `State["PreviousStateGuid"] in StateHistory Set `State["PreviousStateGuid"] in StateHistory Jun 13, 2024
@agrare agrare removed the wip label Jun 13, 2024
@miq-bot
Copy link
Member

miq-bot commented Jun 13, 2024

Checked commits agrare/floe@ab26e1d~...03140e1 with ruby 2.7.8, rubocop 1.56.3, haml-lint 0.51.0, and yamllint
2 files checked, 0 offenses detected
Everything looks fine. ⭐

@kbrock kbrock self-assigned this Jun 14, 2024
@kbrock kbrock merged commit ff6af0a into ManageIQ:master Jun 14, 2024
5 checks passed
@agrare agrare deleted the set_previous_state_guid branch June 14, 2024 20:02
agrare added a commit that referenced this pull request Jun 20, 2024
Fixed
- ResultPath=$ replaces complete output (#199)
- Fix retrier backoff values (#200)
- Fix Retry issues (#202)
- Add Apache-2.0 license (#217)

Changed
- Update gemspec summary (#205)
- Simpler State#long_name (#204)
- State only modifies Context#state - prep for Map/Parallel (#206)
- Set StateHistory in Workflow not State (#211)
- Make Runner#wait optional (#190)
- Pass credentials around with context (#203)
- Pass context to State without workflow (#216)
- Move the guts of the CLI into a class for easy testing (#220)

Added
- Set State PreviousStateGuid in StateHistory (#208)
- Add a codeclimate config file (#224)
- Add an Execution unique ID to Context (#226)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants