mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* chore: rename RunNextTasks workflow * feat: added a trimmed down type for connector only containing the id * feat: make runNextTask use connectorIdOnly * feat: added isScheduledForDeletion to plugin interface * feat: add scheduledForDeletion at plugin level * feat: refactor manager.Load to take a connector instead of parts of it * feat: saves the connector's scheduledFOrDeletion into the plugin * feat: use plugin.IsScheduledForDeletion instead of loading connector * fix: make e2e tests less flaky * fix: remove config from most request types * feat: (WIP) remove config from runNextTask * fix: remove unneeded method definitions in each plugin * fix: simplify RunNextFlow as anyway we need to change the parameters * fix: add a workflow compatible with previous version for runNextTasks * fix(EN-577): added back RunSendEvents as a deprecated workflow * fix(EN-577): added back RunUpdatePaymentInitiationFromPayment as a deprecated workflow * fix: fix linting directives * fix: replace old usage with refactored one * fix: added back missing deprecated activities * fix: ensure fetch_next_balance works with v3.0 code * fix: simplify a bit the versionning etc * fix: quick refactor before applying solution elsewhere * fix: add back RunSendEvents and RunNextTask child workflows where necessary for backward compatibility * fix: add back missing activity, seems like it's mandatory? * fix: run payment initiation update as child workflow when necessary * fix: missing activy call in test, refine some todos * fix: lint * fix: ensure we always reload plugins into the manager -- so exposing isScheduledForDeletion * fix: ensure we stop storing clear config in temporal * fix: make store config support plain text config * fix: some comments * fix: change runSendEvent workflow to be match what we had in 3.0 * feat: enable worker versionning to avoid workflow from new version to get executed on old code * fix: lint * fix: revert worker versionning * fix: minor code review comments * fix: add context to Encrypt & Decrypt methods * fix: improve lint, add couple tests * fix: use atomic to handle isScheduledForDeletion * fix: make create_events work on migration * fix: avoid returning channel; just send what is needed in runSendEventAsChildWorkflow and runNextTaskAsChildWorkflow * fix: remove extra call to installWorkflow on start plugin * fix: typo in error log line * fix: simplify errChan initialization * fix: clarify feature flag names
201 lines
5.2 KiB
Go
201 lines
5.2 KiB
Go
package workflow
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/formancehq/go-libs/v3/logging"
|
|
temporalworker "github.com/formancehq/go-libs/v3/temporal"
|
|
"github.com/formancehq/payments/internal/connectors"
|
|
"go.temporal.io/sdk/client"
|
|
"go.temporal.io/sdk/workflow"
|
|
)
|
|
|
|
const (
|
|
SearchAttributeScheduleID = "PaymentScheduleID"
|
|
SearchAttributeStack = "Stack"
|
|
)
|
|
|
|
type FromPayload struct {
|
|
ID string `json:"id"`
|
|
Payload json.RawMessage `json:"payload"`
|
|
}
|
|
|
|
func (f *FromPayload) GetPayload() json.RawMessage {
|
|
if f == nil {
|
|
return nil
|
|
}
|
|
return f.Payload
|
|
}
|
|
|
|
type Workflow struct {
|
|
temporalNamespace string
|
|
temporalClient client.Client
|
|
|
|
connectors connectors.Manager
|
|
|
|
stackPublicURL string
|
|
stack string
|
|
|
|
logger logging.Logger
|
|
}
|
|
|
|
func New(temporalClient client.Client, temporalNamespace string, connectors connectors.Manager, stack string, stackPublicURL string, logger logging.Logger) Workflow {
|
|
return Workflow{
|
|
temporalClient: temporalClient,
|
|
temporalNamespace: temporalNamespace,
|
|
connectors: connectors,
|
|
stack: stack,
|
|
stackPublicURL: stackPublicURL,
|
|
logger: logger,
|
|
}
|
|
}
|
|
|
|
func (w Workflow) DefinitionSet() temporalworker.DefinitionSet {
|
|
return temporalworker.NewDefinitionSet().
|
|
Append(temporalworker.Definition{
|
|
Name: RunFetchNextAccounts,
|
|
Func: w.runFetchNextAccounts,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunFetchNextBalances,
|
|
Func: w.runFetchNextBalances,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunFetchNextExternalAccounts,
|
|
Func: w.runFetchNextExternalAccounts,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunFetchNextOthers,
|
|
Func: w.runFetchNextOthers,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunFetchNextPayments,
|
|
Func: w.runFetchNextPayments,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunListActiveSchedules,
|
|
Func: w.runListActiveSchedules,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunUpdateSchedulePollingPeriod,
|
|
Func: w.runUpdateSchedulePollingPeriod,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunTerminateScheduleByID,
|
|
Func: w.runTerminateScheduleByID,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunTerminateSchedules,
|
|
Func: w.runTerminateSchedules,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunTerminateWorkflows,
|
|
Func: w.runTerminateWorkflows,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunInstallConnector,
|
|
Func: w.runInstallConnector,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunResetConnector,
|
|
Func: w.runResetConnector,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunUninstallConnector,
|
|
Func: w.runUninstallConnector,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunCreateBankAccount,
|
|
Func: w.runCreateBankAccount,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunCreatePayout,
|
|
Func: w.runCreatePayout,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunReversePayout,
|
|
Func: w.runReversePayout,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunPollPayout,
|
|
Func: w.runPollPayout,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunCreateTransfer,
|
|
Func: w.runCreateTransfer,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunReverseTransfer,
|
|
Func: w.runReverseTransfer,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunPollTransfer,
|
|
Func: w.runPollTransfer,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunNextTasksV3_1,
|
|
Func: w.runNextTasksV3_1,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunCreateWebhooks,
|
|
Func: w.runCreateWebhooks,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunHandleWebhooks,
|
|
Func: w.runHandleWebhooks,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunStoreWebhookTranslation,
|
|
Func: w.runStoreWebhookTranslation,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunDeletePSU,
|
|
Func: w.runDeletePSU,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunDeletePSUConnector,
|
|
Func: w.runDeletePSUConnector,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunDeleteConnection,
|
|
Func: w.runDeleteConnection,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunCompleteUserLink,
|
|
Func: w.runCompleteUserLink,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunFetchOpenBankingData,
|
|
Func: w.runFetchOpenBankingData,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunDeleteOpenBankingConnectionData,
|
|
Func: w.runDeleteOpenBankingConnectionData,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunOutboxPublisher,
|
|
Func: w.runOutboxPublisher,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunOutboxCleanup,
|
|
Func: w.runOutboxCleanup,
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunNextTasks, //nolint:staticcheck
|
|
Func: w.runNextTasks, //nolint:staticcheck
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunSendEvents, //nolint:staticcheck // ignore deprecation
|
|
Func: w.runSendEvents, //nolint:staticcheck // ignore deprecation
|
|
}).
|
|
Append(temporalworker.Definition{
|
|
Name: RunUpdatePaymentInitiationFromPayment, //nolint:staticcheck // ignore deprecation
|
|
Func: w.runUpdatePaymentInitiationFromPayment, //nolint:staticcheck // ignore deprecation
|
|
})
|
|
}
|
|
|
|
func (w Workflow) shouldContinueAsNew(ctx workflow.Context) bool {
|
|
workflowInfo := workflow.GetInfo(ctx)
|
|
return workflowInfo.GetContinueAsNewSuggested()
|
|
}
|