Skip to content

Commit 0d3c677

Browse files
committed
fix child workflow invocation
1 parent 7312571 commit 0d3c677

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

server/internal/background/deployments.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func ProcessDeploymentWorkflow(ctx workflow.Context, params ProcessDeploymentWor
193193
string(attr.DeploymentIDKey), params.DeploymentID,
194194
)
195195
_, err = ExecuteProjectFunctionsReaperChildWorkflow(ctx, params.ProjectID)
196-
if err != nil {
196+
if err != nil && !temporal.IsWorkflowExecutionAlreadyStartedError(err) {
197197
logger.Error(
198198
"failed to start project-scoped functions reaper workflow",
199199
"error", err.Error(),

server/internal/background/functions_reaper.go

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package background
22

33
import (
4-
"context"
54
"fmt"
65
"time"
76

87
"go.temporal.io/api/enums/v1"
9-
"go.temporal.io/sdk/client"
108
"go.temporal.io/sdk/temporal"
119
"go.temporal.io/sdk/workflow"
1210

@@ -26,29 +24,19 @@ type FunctionsReaperWorkflowResult struct {
2624
}
2725

2826
func ExecuteProjectFunctionsReaperChildWorkflow(ctx workflow.Context, projectID uuid.UUID) (workflow.ChildWorkflowFuture, error) {
29-
return workflow.ExecuteChildWorkflow(ctx, client.StartWorkflowOptions{
30-
ID: "v1:functions-reaper:" + projectID.String(),
31-
TaskQueue: string(TaskQueueMain),
32-
WorkflowIDConflictPolicy: enums.WORKFLOW_ID_CONFLICT_POLICY_USE_EXISTING,
33-
WorkflowIDReusePolicy: enums.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE,
34-
WorkflowRunTimeout: time.Minute * 5,
35-
}, FunctionsReaperWorkflow, FunctionsReaperWorkflowParams{
27+
ctx = workflow.WithChildOptions(ctx, workflow.ChildWorkflowOptions{
28+
WorkflowID: "v1:functions-reaper:" + projectID.String(),
29+
TaskQueue: string(TaskQueueMain),
30+
WorkflowIDReusePolicy: enums.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY,
31+
WorkflowRunTimeout: time.Minute * 10,
32+
})
33+
34+
return workflow.ExecuteChildWorkflow(ctx, FunctionsReaperWorkflow, FunctionsReaperWorkflowParams{
3635
Scope: activities.FunctionsReaperScopeProject,
3736
ProjectID: uuid.NullUUID{UUID: projectID, Valid: projectID != uuid.Nil},
3837
}), nil
3938
}
4039

41-
func ExecuteFunctionsReaperWorkflow(ctx context.Context, temporalClient client.Client, params FunctionsReaperWorkflowParams) (client.WorkflowRun, error) {
42-
// Use a fixed workflow ID so that only one reaper workflow can run at a time
43-
return temporalClient.ExecuteWorkflow(ctx, client.StartWorkflowOptions{
44-
ID: "v1:functions-reaper",
45-
TaskQueue: string(TaskQueueMain),
46-
WorkflowIDConflictPolicy: enums.WORKFLOW_ID_CONFLICT_POLICY_USE_EXISTING,
47-
WorkflowIDReusePolicy: enums.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE,
48-
WorkflowRunTimeout: time.Minute * 10,
49-
}, FunctionsReaperWorkflow, params)
50-
}
51-
5240
func FunctionsReaperWorkflow(ctx workflow.Context, params FunctionsReaperWorkflowParams) (*FunctionsReaperWorkflowResult, error) {
5341
// This can stay nil/unassigned. Temporal just uses this to get activity names.
5442
// The actual activities are registered in the CLI layer (cmd/gram/worker.go).

0 commit comments

Comments
 (0)