-
Notifications
You must be signed in to change notification settings - Fork 10
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) 2022, Salesforce, Inc. | ||
// All rights reserved. | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
|
||
package orchard | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
type Details struct { | ||
Id string `json:"id" binding:"required"` | ||
Name string `json:"name" binding:"required"` | ||
Status string `json:"status" binding:"required"` | ||
CreatedAt string `json:"createdAt" binding:"required"` | ||
} | ||
|
||
func ParseDetails(resp []byte) (*Details, error) { | ||
var data Details | ||
err := json.Unmarshal(resp, &data) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to decode the response: %v", err) | ||
} | ||
return &data, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2022, Salesforce, Inc. | ||
// All rights reserved. | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
|
||
package orchard | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestDetails(t *testing.T) { | ||
wfId := "wf-e7901f9f-8e88-4173-9d6e-d63f8b1e647f" | ||
wfName := "test.workflow" | ||
wfStats := "pending" | ||
wfCreatedAt := "2024-12-12T02:12:19.260463" | ||
wfStr := fmt.Sprintf(`{"id":"%s","name":"%s","status":"%s","createdAt":"%s"}`, wfId, wfName, wfStats, wfCreatedAt) | ||
resp := []byte(wfStr) | ||
details, err := ParseDetails(resp) | ||
if err != nil { | ||
t.Fatalf("unable to parse response: %v", err) | ||
} | ||
if details.Id != wfId { | ||
t.Fatalf("parsed %s doesn't match %s", details.Id, wfId) | ||
} | ||
if details.Name != wfName { | ||
t.Fatalf("parsed %s doesn't match %s", details.Name, wfName) | ||
} | ||
if details.Status != wfStats { | ||
t.Fatalf("parsed %s doesn't match %s", details.Status, wfStats) | ||
} | ||
if details.CreatedAt != wfCreatedAt { | ||
t.Fatalf("parsed %s doesn't match %s", details.CreatedAt, wfCreatedAt) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should just change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@schowsf yeah, can add a nil check before |
||
return Activated.ToString() | ||
} | ||
fmt.Printf("[error] error activating workflow (name: %s, orchard_id: %s): %s\n", wf.Name, swf.OrchardID, err) | ||
notifyOwner(wf, err) | ||
return swf.Status | ||
|
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.
make sure you close the body afterwards with
defer rsp.Body.Close()
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.
Got it. Thanks