diff --git a/backend/postgres/postgres.go b/backend/postgres/postgres.go index e8c9b6f..ba4f17e 100644 --- a/backend/postgres/postgres.go +++ b/backend/postgres/postgres.go @@ -361,7 +361,10 @@ func (be *postgresBackend) CompleteOrchestrationWorkItem(ctx context.Context, wi for _, msg := range wi.State.PendingMessages() { if es := msg.HistoryEvent.GetExecutionStarted(); es != nil { // Need to insert a new row into the DB - if _, err := be.createOrchestrationInstanceInternal(ctx, msg.HistoryEvent, tx); err != nil { + if _, err := be.createOrchestrationInstanceInternal(ctx, msg.HistoryEvent, tx, backend.WithOrchestrationIdReusePolicy(&protos.OrchestrationIdReusePolicy{ + OperationStatus: []protos.OrchestrationStatus{protos.OrchestrationStatus_ORCHESTRATION_STATUS_FAILED}, + Action: api.REUSE_ID_ACTION_TERMINATE, + })); err != nil { if errors.Is(err, backend.ErrDuplicateEvent) { be.logger.Warnf( "%v: dropping sub-orchestration creation event because an instance with the target ID (%v) already exists.",