Files
zeekay 7d727874d5 chore: rebrand Formance Payments -> Hanzo Payments (hanzo-fi)
- 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.
2026-07-05 13:08:55 -07:00

153 lines
4.0 KiB
Go

package workflow
import (
"fmt"
"github.com/hanzo-fi/payments/internal/connectors/engine/activities"
"github.com/hanzo-fi/payments/internal/connectors/plugins/registry"
"github.com/hanzo-fi/payments/pkg/domain/models"
"github.com/pkg/errors"
"go.temporal.io/sdk/workflow"
)
type FetchNextOthers struct {
ConnectorID models.ConnectorID `json:"connectorID"`
Name string `json:"name"`
FromPayload *FromPayload `json:"fromPayload"`
Periodically bool `json:"periodically"`
}
func (w Workflow) runFetchNextOthers(
ctx workflow.Context,
fetchNextOthers FetchNextOthers,
nextTasks []models.ConnectorTaskTree,
) error {
if err := w.createInstance(ctx, fetchNextOthers.ConnectorID); err != nil {
return errors.Wrap(err, "creating instance")
}
err := w.fetchNextOthers(ctx, fetchNextOthers, nextTasks)
return w.terminateInstance(ctx, fetchNextOthers.ConnectorID, err)
}
func (w Workflow) fetchNextOthers(
ctx workflow.Context,
fetchNextOthers FetchNextOthers,
nextTasks []models.ConnectorTaskTree,
) error {
stateReference := models.CAPABILITY_FETCH_OTHERS.String()
if fetchNextOthers.FromPayload != nil {
stateReference = fmt.Sprintf("%s-%s", models.CAPABILITY_FETCH_OTHERS.String(), fetchNextOthers.FromPayload.ID)
}
stateID := models.StateID{
Reference: stateReference,
ConnectorID: fetchNextOthers.ConnectorID,
}
state, err := activities.StorageStatesGet(infiniteRetryContext(ctx), stateID)
if err != nil {
return fmt.Errorf("retrieving state %s: %v", stateID.String(), err)
}
// Get pageSize from registry using provider from ConnectorID (no DB call needed)
pageSize, err := registry.GetPageSize(fetchNextOthers.ConnectorID.Provider)
if err != nil {
return fmt.Errorf("getting page size: %w", err)
}
hasMore := true
for hasMore {
othersResponse, err := activities.PluginFetchNextOthers(
infiniteRetryWithLongTimeoutContext(ctx),
fetchNextOthers.ConnectorID,
fetchNextOthers.Name,
fetchNextOthers.FromPayload.GetPayload(),
state.State,
int(pageSize),
fetchNextOthers.Periodically,
)
if err != nil {
return errors.Wrap(err, "fetching next others")
}
wg := workflow.NewWaitGroup(ctx)
errChan := make(chan error, len(othersResponse.Others))
if !IsRunNextTaskOptimizationsEnabled(ctx) {
for _, other := range othersResponse.Others {
o := other
fromPayload := &FromPayload{
ID: o.ID,
Payload: o.Other,
}
w.runNextTaskAsChildWorkflow(ctx, fetchNextOthers.ConnectorID, nextTasks, wg, fromPayload, errChan)
}
} else if len(nextTasks) > 0 {
// First, we need to get the connector to check if it is scheduled for deletion
// because if it is, we don't need to run the next tasks
plugin, err := w.connectors.Get(fetchNextOthers.ConnectorID)
if err != nil {
return fmt.Errorf("getting connector: %w", err)
}
if !plugin.IsScheduledForDeletion() {
for _, other := range othersResponse.Others {
o := other
wg.Add(1)
workflow.Go(ctx, func(ctx workflow.Context) {
defer wg.Done()
if err := w.runNextTasksV3_1(
ctx,
fetchNextOthers.ConnectorID,
&FromPayload{
ID: o.ID,
Payload: o.Other,
},
nextTasks,
); err != nil {
errChan <- errors.Wrap(err, "running next tasks")
}
})
}
}
}
wg.Wait(ctx)
close(errChan)
for err := range errChan {
if err != nil {
return err
}
}
state.State = othersResponse.NewState
err = activities.StorageStatesStore(
infiniteRetryContext(ctx),
*state,
)
if err != nil {
return errors.Wrap(err, "storing state")
}
hasMore = othersResponse.HasMore
if w.shouldContinueAsNew(ctx) {
// If we have lots and lots of accounts, sometimes, we need to
// continue as new to not exeed the maximum history size or length
// of a workflow.
return workflow.NewContinueAsNewError(
ctx,
RunFetchNextOthers,
fetchNextOthers,
nextTasks,
)
}
}
return nil
}
const RunFetchNextOthers = "FetchOthers"