Files
fgueryandGitHub 599477b709 fix(EN-549): remove config and connector dependencies (#622)
* 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
2026-01-05 11:09:45 +00:00

122 lines
2.8 KiB
Go

package workflow
import (
"fmt"
"github.com/formancehq/payments/internal/connectors/engine/activities"
"github.com/formancehq/payments/internal/connectors/engine/utils"
"github.com/formancehq/payments/internal/models"
"github.com/pkg/errors"
"go.temporal.io/sdk/workflow"
)
type CreateWebhooks struct {
ConnectorID models.ConnectorID
FromPayload *FromPayload
}
func (w Workflow) runCreateWebhooks(
ctx workflow.Context,
createWebhooks CreateWebhooks,
nextTasks []models.ConnectorTaskTree,
) error {
return w.createWebhooks(ctx, createWebhooks, nextTasks)
}
func (w Workflow) createWebhooks(
ctx workflow.Context,
createWebhooks CreateWebhooks,
nextTasks []models.ConnectorTaskTree,
) error {
webhookBaseURL, err := utils.GetWebhookBaseURL(w.stackPublicURL, createWebhooks.ConnectorID)
if err != nil {
return fmt.Errorf("joining webhook base URL: %w", err)
}
resp, err := activities.PluginCreateWebhooks(
infiniteRetryContext(ctx),
createWebhooks.ConnectorID,
models.CreateWebhooksRequest{
WebhookBaseUrl: webhookBaseURL,
ConnectorID: createWebhooks.ConnectorID.String(),
FromPayload: createWebhooks.FromPayload.GetPayload(),
},
)
if err != nil {
return fmt.Errorf("failed to create webhooks: %w", err)
}
if len(resp.Configs) > 0 {
configs := make([]models.WebhookConfig, 0, len(resp.Configs))
for _, c := range resp.Configs {
configs = append(configs, models.WebhookConfig{
Name: c.Name,
ConnectorID: createWebhooks.ConnectorID,
URLPath: c.URLPath,
Metadata: c.Metadata,
})
}
err = activities.StorageWebhooksConfigsStore(
infiniteRetryContext(ctx),
configs,
)
if err != nil {
return fmt.Errorf("storing webhooks: %w", err)
}
}
plugin, err := w.connectors.Get(createWebhooks.ConnectorID)
if err != nil {
return fmt.Errorf("getting connector: %w", err)
}
wg := workflow.NewWaitGroup(ctx)
errChan := make(chan error, len(resp.Others)*2)
if !IsRunNextTaskOptimizationsEnabled(ctx) {
for _, other := range resp.Others {
o := other
payload := &FromPayload{
ID: o.ID,
Payload: o.Other,
}
w.runNextTaskAsChildWorkflow(ctx, createWebhooks.ConnectorID, nextTasks, wg, payload, errChan)
}
} else {
if !plugin.IsScheduledForDeletion() {
for _, other := range resp.Others {
o := other
wg.Add(1)
workflow.Go(ctx, func(ctx workflow.Context) {
defer wg.Done()
if err := w.runNextTasksV3_1(
ctx,
createWebhooks.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
}
}
return nil
}
const RunCreateWebhooks = "RunCreateWebhooks"