mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
- go.mod module path + all self-imports: github.com/formancehq/payments -> github.com/hanzo-fi/payments (1590 .go files / 3152 refs; 20 modules: root, pkg/client, pkg/domain, 18 ce/plugins). External dep kept: formancehq/go-libs. - plugins: each ce/plugins/* consumed a *published* pkg/domain; added local 'replace .../pkg/domain => ../../../pkg/domain' (consistent with root) so every standalone plugin module builds in-monorepo. compile-plugin.sh MOD var rebranded too. - branding: README, LICENSE (dual MIT+EE; upstream copyright retained + Hanzo added), goreleaser (release images -> registry.hanzo.ai/hanzo-fi, OCI labels, homepage), proto go_package, renovate, speakeasy gen.yaml, connector-template *.gotpl. - CI: removed Numary/Formance workflows + composite action; added canonical hanzo.yml + cicd.yml (hanzoai/ci, gated HANZO_CI_ENABLED) + secretless ci.yml (go build/vet). - kept as data/compat keys: wire capability enums ALLOW_FORMANCE_*, generated SDK type client.Formance, domain field FormanceRedirectURL, OTEL_SERVICE_NAME, upstream base image. - verified: go build ./... (default + -tags ee) + all 20 nested modules green.
104 lines
2.7 KiB
Go
104 lines
2.7 KiB
Go
package workflow
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hanzo-fi/payments/internal/connectors/engine/activities"
|
|
"github.com/hanzo-fi/payments/pkg/domain/models"
|
|
"go.temporal.io/api/enums/v1"
|
|
"go.temporal.io/api/workflowservice/v1"
|
|
"go.temporal.io/sdk/workflow"
|
|
)
|
|
|
|
type TerminateWorkflows struct {
|
|
ConnectorID models.ConnectorID
|
|
NextPageToken []byte
|
|
}
|
|
|
|
func (w Workflow) runTerminateWorkflows(
|
|
ctx workflow.Context,
|
|
terminateWorkflows TerminateWorkflows,
|
|
) error {
|
|
var nextPageToken = terminateWorkflows.NextPageToken
|
|
|
|
for {
|
|
resp, err := activities.TemporalWorkflowExecutionsList(
|
|
infiniteRetryContext(ctx),
|
|
&workflowservice.ListWorkflowExecutionsRequest{
|
|
Namespace: w.temporalNamespace,
|
|
PageSize: 100,
|
|
NextPageToken: nextPageToken,
|
|
Query: fmt.Sprintf("Stack=\"%s\" and ConnectorID=\"%s\"", w.stack, terminateWorkflows.ConnectorID.String()),
|
|
},
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
currentInfo := workflow.GetInfo(ctx)
|
|
wg := workflow.NewWaitGroup(ctx)
|
|
errChan := make(chan error, len(resp.Executions))
|
|
for _, e := range resp.Executions {
|
|
if e.Status != enums.WORKFLOW_EXECUTION_STATUS_RUNNING {
|
|
continue
|
|
}
|
|
|
|
// Never terminate the uninstall or reset workflows — they are
|
|
// responsible for driving the teardown and must not be cut short.
|
|
if e.Type != nil && (e.Type.Name == RunUninstallConnector || e.Type.Name == RunResetConnector || e.Type.Name == RunTerminateSchedules) {
|
|
continue
|
|
}
|
|
|
|
// Never terminate ourselves.
|
|
if e.Execution != nil && e.Execution.WorkflowId == currentInfo.WorkflowExecution.ID &&
|
|
e.Execution.RunId == currentInfo.WorkflowExecution.RunID {
|
|
continue
|
|
}
|
|
|
|
wg.Add(1)
|
|
workflow.Go(ctx, func(ctx workflow.Context) {
|
|
defer wg.Done()
|
|
|
|
if err := activities.TemporalWorkflowTerminate(
|
|
infiniteRetryContext(ctx),
|
|
e.Execution.WorkflowId,
|
|
e.Execution.RunId,
|
|
"uninstalling connector",
|
|
); err != nil {
|
|
errChan <- err
|
|
}
|
|
})
|
|
}
|
|
|
|
wg.Wait(ctx)
|
|
close(errChan)
|
|
|
|
for err := range errChan {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if resp.NextPageToken == nil {
|
|
break
|
|
}
|
|
|
|
nextPageToken = resp.NextPageToken
|
|
|
|
if w.shouldContinueAsNew(ctx) {
|
|
// Because we can have lots and lots of workflows, sometimes, we
|
|
// will exceed the maximum history size or length of a workflow.
|
|
// When that arrive, the workflow will be forced to terminate.
|
|
// We need to continue as new to avoid this.
|
|
return workflow.NewContinueAsNewError(ctx, RunTerminateWorkflows, TerminateWorkflows{
|
|
ConnectorID: terminateWorkflows.ConnectorID,
|
|
NextPageToken: nextPageToken,
|
|
})
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
const RunTerminateWorkflows = "TerminateWorkflows"
|