-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drop_flow: drop destination/source concurrently
Avoids destination issues blocking source cleanup, along with being a bit faster Also cleanup identifier escaping in external_metadata/store.go
- Loading branch information
Showing
4 changed files
with
36 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,37 @@ | ||
package peerflow | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/PeerDB-io/peer-flow/generated/protos" | ||
"github.com/PeerDB-io/peer-flow/shared" | ||
"go.temporal.io/sdk/log" | ||
"go.temporal.io/sdk/workflow" | ||
) | ||
|
||
// DropFlowWorkflowExecution represents the state for execution of a drop flow. | ||
type DropFlowWorkflowExecution struct { | ||
shutDownRequest *protos.ShutdownRequest | ||
flowExecutionID string | ||
logger log.Logger | ||
} | ||
|
||
func newDropFlowWorkflowExecution(ctx workflow.Context, req *protos.ShutdownRequest) *DropFlowWorkflowExecution { | ||
return &DropFlowWorkflowExecution{ | ||
shutDownRequest: req, | ||
flowExecutionID: workflow.GetInfo(ctx).WorkflowExecution.ID, | ||
logger: workflow.GetLogger(ctx), | ||
} | ||
} | ||
|
||
func DropFlowWorkflow(ctx workflow.Context, req *protos.ShutdownRequest) error { | ||
execution := newDropFlowWorkflowExecution(ctx, req) | ||
execution.logger.Info("performing cleanup for flow ", req.FlowJobName) | ||
logger := workflow.GetLogger(ctx) | ||
logger.Info("performing cleanup for flow ", req.FlowJobName) | ||
|
||
ctx = workflow.WithActivityOptions(ctx, workflow.ActivityOptions{ | ||
StartToCloseTimeout: 1 * time.Minute, | ||
}) | ||
|
||
ctx = workflow.WithValue(ctx, shared.FlowNameKey, req.FlowJobName) | ||
dropSourceFuture := workflow.ExecuteActivity(ctx, flowable.DropFlowSource, req) | ||
dropDestinationFuture := workflow.ExecuteActivity(ctx, flowable.DropFlowDestination, req) | ||
|
||
dropFlowFuture := workflow.ExecuteActivity(ctx, flowable.DropFlow, req) | ||
if err := dropFlowFuture.Get(ctx, nil); err != nil { | ||
return err | ||
} | ||
var sourceError, destinationError error | ||
selector := workflow.NewNamedSelector(ctx, fmt.Sprintf("%s-drop", req.FlowJobName)) | ||
selector.AddFuture(dropSourceFuture, func(f workflow.Future) { | ||
sourceError = f.Get(ctx, nil) | ||
}) | ||
selector.AddFuture(dropDestinationFuture, func(f workflow.Future) { | ||
destinationError = f.Get(ctx, nil) | ||
}) | ||
selector.Select(ctx) | ||
selector.Select(ctx) | ||
|
||
return nil | ||
return errors.Join(sourceError, destinationError) | ||
} |