-
Notifications
You must be signed in to change notification settings - Fork 1.3k
State machine for CHASM activities #8496
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
State machine for CHASM activities #8496
Conversation
| var _ chasm.StateMachine[activitypb.ActivityExecutionStatus] = (*Activity)(nil) | ||
|
|
||
| // State returns the current status of the activity. | ||
| func (a *Activity) State() activitypb.ActivityExecutionStatus { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we change the state machine abstraction to expect Status and SetStatus as it seems we are converging on that terminology?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I like that. I feel that this makes sense:
- A state machine library has
State()andSetState() - For a given client of that library, "status" is the field name used for the state that is governed by the state machine library.
chasm/lib/activity/statemachine.go
Outdated
| if a.ActivityState == nil { | ||
| return | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let it panic, this should be an invalid state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| "go.temporal.io/server/chasm/lib/activity/gen/activitypb/v1" | ||
| ) | ||
|
|
||
| func TestValidTransitions(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this type of test, you are just testing configuration here and duplicating what is defined in the code being tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree! Deleted test. We'll start having test coverage when we add the API method PRs.
| } | ||
| } | ||
|
|
||
| func TestInvalidTransitions(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
chasm/lib/activity/statemachine.go
Outdated
| a.ActivityState.Status = state | ||
| } | ||
|
|
||
| var ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you get rid of this redundant nesting? By the time you get to the function implementation, you're three levels in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
chasm/lib/activity/statemachine.go
Outdated
| activitypb.ACTIVITY_EXECUTION_STATUS_UNSPECIFIED, | ||
| }, | ||
| activitypb.ACTIVITY_EXECUTION_STATUS_SCHEDULED, | ||
| func(_ chasm.MutableContext, _ *Activity, _ any) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be nice to change the transition function's signature to take SM as the first argument so you can pass a method pointer here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like a good idea. Done.
chasm/lib/activity/statemachine.go
Outdated
| } | ||
|
|
||
| var ( | ||
| TransitionScheduled = chasm.NewTransition( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add some docstrings to explain what this is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes good call, done.
e518ec7 to
984ed80
Compare
984ed80 to
f722d1c
Compare
|
Ready for review again |
bergundy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but you'll want to rebase and not include the proto changes here.
193fa7f to
59cd168
Compare
Adds a state machine defining valid transitions for a CHASM activity. The state machine does not include transitions related to cancel and pause states: we can add those when we implement those features. Part of foundations for CHASM activity implementation / Standalone Activity. - Built (a unit test was written but not committed)
Adds a state machine defining valid transitions for a CHASM activity. The state machine does not include transitions related to cancel and pause states: we can add those when we implement those features. Part of foundations for CHASM activity implementation / Standalone Activity. - Built (a unit test was written but not committed)
What changed?
Adds a state machine defining valid transitions for a CHASM activity.
The state machine does not include transitions related to cancel and pause states: we can add those when we implement those features.
Why?
Part of foundations for CHASM activity implementation / Standalone Activity.
How did you test it?
Note
Introduces an Activity state machine with core execution transitions and updates the chasm Transition API to take (SM, Context, Event) parameter order.
chasm/lib/activity/statemachine.go):activity.Activityaschasm.StateMachine[activitypb.ActivityExecutionStatus]withState()/SetState().UNSPECIFIED -> SCHEDULEDSCHEDULED -> STARTEDSTARTED -> COMPLETED | FAILEDSCHEDULED | STARTED -> TERMINATED | TIMED_OUTchasm/statemachine.go):Transition.applysignature toapply(SM, MutableContext, E)and updatesNewTransition/Applyaccordingly.Written by Cursor Bugbot for commit 59cd168. This will update automatically on new commits. Configure here.