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

check wf status to avoid infinite loops #45

Merged
merged 5 commits into from
Dec 18, 2024
Merged

Conversation

crm-dhu
Copy link
Contributor

@crm-dhu crm-dhu commented Dec 14, 2024

No description provided.

@crm-dhu
Copy link
Contributor Author

crm-dhu commented Dec 14, 2024

@realstraw please review it.

@crm-dhu
Copy link
Contributor Author

crm-dhu commented Dec 14, 2024

@damianxu88 @schowsf Please review.

return false, err
}
if resp.StatusCode != http.StatusOK {
return false, fmt.Errorf("workflow %s is not found", orchardID)
Copy link
Contributor

Choose a reason for hiding this comment

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

not found should be 404, probably not a good idea to treat all non 200 response as 404

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.

resp, err := c.Details(orchardID)
if err != nil {
return false, err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

make sure you close the body afterwards with defer rsp.Body.Close()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. Thanks

@@ -86,6 +86,33 @@ func (c OrchardRestClient) create(result string) (string, error) {
return string(orchardID), nil
}

func (c OrchardRestClient) IsActivated(orchardID string) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make it to Details and return parsed details instead. Whoever is calling this should deal with what status it returns

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -158,6 +158,10 @@ func (s *Scheduler) activateWorkflow(
wf table.Workflow,
) string {
if err := client.Activate(swf.OrchardID); err != nil {
isActivated, err2 := client.IsActivated(swf.OrchardID)
Copy link
Contributor

Choose a reason for hiding this comment

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

where is the infinite loop coming from? it's activated but sprinkler think it's not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, when a wf is activated but sprinkler thinks it's not and keeps activating the wf in every second.

@@ -158,6 +158,10 @@ func (s *Scheduler) activateWorkflow(
wf table.Workflow,
) string {
if err := client.Activate(swf.OrchardID); err != nil {
details, err2 := client.Details(swf.OrchardID)
if err2 == nil && details.Status != "pending" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

could details be nil? does it need a nil check before details.Status

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should just change client.Activate to check the return code upon error and send a Detail call, instead of doing it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

could details be nil? does it need a nil check before details.Status

@schowsf yeah, can add a nil check before details.Status

@realstraw realstraw merged commit 3beabf7 into salesforce:main Dec 18, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants