mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* fix: (temporal) skip deleting workflows when they are already completed or not found * test: (temporal) add test and mocks for schedule deletion activity
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package activities
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"go.temporal.io/api/serviceerror"
|
|
"go.temporal.io/sdk/temporal"
|
|
"go.temporal.io/sdk/workflow"
|
|
)
|
|
|
|
func (a Activities) TemporalScheduleDelete(ctx context.Context, scheduleID string) error {
|
|
handle := a.temporalClient.ScheduleClient().GetHandle(ctx, scheduleID)
|
|
err := handle.Delete(ctx)
|
|
if err != nil {
|
|
var applicationErr *temporal.ApplicationError
|
|
var notFoundErr *serviceerror.NotFound
|
|
if errors.As(err, &applicationErr) {
|
|
switch applicationErr.Type() {
|
|
case "NotFound":
|
|
return nil
|
|
default:
|
|
return err
|
|
}
|
|
} else if errors.As(err, ¬FoundErr) {
|
|
// if the workflow is already done or doesn't exist in temporal server we can safely move on
|
|
a.logger.Debugf("skipping deletion of schedule %q due to service error: %s", scheduleID, err.Error())
|
|
return nil
|
|
}
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
var TemporalScheduleDeleteActivity = Activities{}.TemporalScheduleDelete
|
|
|
|
func TemporalScheduleDelete(ctx workflow.Context, scheduleID string) error {
|
|
return executeActivity(ctx, TemporalScheduleDeleteActivity, nil, scheduleID)
|
|
}
|