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

feat: add retry metadata to fsm decl #1554

Merged
merged 7 commits into from
May 27, 2024
Merged

Conversation

matt2e
Copy link
Collaborator

@matt2e matt2e commented May 22, 2024

Changes:

  • Extract retries metadata declared for a FSM. The idea is that this will be the default retry policy for each transition, but that is out of scope for this PR.
  • Traversing the ast graph now provides a stack of nodes rather than just the current node (so we can derive info based on parent nodes, rather than maintaining that state with special cases)
    • removed currentVerb from parserContext as this special case is no longer needed

Add retries to a FSM like this:

// The payment FSM.
//
//ftl:retry 10 5s 10m
var paymentFSM = ftl.FSM("payment",
	ftl.Start(Created),
	ftl.Start(Paid),
	ftl.Transition(Created, Paid),
	ftl.Transition(Created, Failed),
	ftl.Transition(Paid, Completed),
)

In the schema it looks like this:

fsm payment
   +retry 10 5s 10m
{
   start fsm.created
   start fsm.paid
   transition fsm.created to fsm.paid
   transition fsm.created to fsm.failed
   transition fsm.paid to fsm.completed
}

@ftl-robot ftl-robot mentioned this pull request May 22, 2024
@alecthomas
Copy link
Collaborator

alecthomas commented May 22, 2024

In goast, there is no relationship between ftl.FSM(...) and the comment group, so this PR makes a map of line number to comment group node, which we can then look up when we find the FSM function call.

You should be able to find variable declarations of the FSM type, then get the comments from the variable no?

@alecthomas
Copy link
Collaborator

How should retries for FSMs show up in schema?

I like this syntax 👍

@matt2e matt2e force-pushed the matt2e/fsm-retry-directives branch from dcc26cc to 76d58a1 Compare May 24, 2024 03:41
@matt2e
Copy link
Collaborator Author

matt2e commented May 24, 2024

In goast, there is no relationship between ftl.FSM(...) and the comment group, so this PR makes a map of line number to comment group node, which we can then look up when we find the FSM function call.

You should be able to find variable declarations of the FSM type, then get the comments from the variable no?

Ah you're right, the variable declaration holds the documentation.
I've made Visit() provide a stack which makes this a lot easier to do. And it removes the need for parserContext to track activeVerb

return visitStack([]goast.Node{node}, v)
}

func visitStack(stack []goast.Node, v VisitorFunc) error { //nolint:maintidx
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

regex did the dirty work here, no RSI was harmed

@matt2e matt2e force-pushed the matt2e/fsm-retry-directives branch from 2f488b7 to 0c3ac79 Compare May 24, 2024 04:12
@matt2e matt2e marked this pull request as ready for review May 24, 2024 04:19
@matt2e matt2e requested a review from alecthomas as a code owner May 24, 2024 04:19
@matt2e matt2e requested review from a team and worstell and removed request for a team May 24, 2024 04:19
@matt2e matt2e mentioned this pull request May 24, 2024
3 tasks
@matt2e matt2e force-pushed the matt2e/fsm-retry-directives branch 2 times, most recently from 2e46f92 to a228f5e Compare May 27, 2024 06:33
@matt2e matt2e force-pushed the matt2e/fsm-retry-directives branch from a228f5e to 6ea925e Compare May 27, 2024 23:21
@matt2e matt2e merged commit 9993dee into main May 27, 2024
25 checks passed
@matt2e matt2e deleted the matt2e/fsm-retry-directives branch May 27, 2024 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants