Skip to content

Commit

Permalink
fix: triggers with metadata (#981)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Dec 8, 2023
1 parent 19b6fb5 commit bd45537
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions components/orchestration/internal/triggers/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/formancehq/orchestration/internal/workflow"
"github.com/formancehq/stack/libs/go-libs/logging"
"github.com/formancehq/stack/libs/go-libs/pointer"
"github.com/uptrace/bun"
)
Expand Down Expand Up @@ -35,6 +36,10 @@ func (a Activities) ListTriggers(ctx context.Context, request ProcessEventReques
}
}

logging.FromContext(ctx).
WithField("trigger-id", trigger.ID).
Debugf("Checking expr '%s': %v", trigger.Filter, ok)

if ok {
ret = append(ret, trigger)
}
Expand Down
7 changes: 2 additions & 5 deletions components/orchestration/internal/triggers/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"encoding/json"
"fmt"

"github.com/formancehq/stack/libs/go-libs/pointer"
"go.temporal.io/api/enums/v1"

"github.com/formancehq/stack/libs/go-libs/pointer"
"go.temporal.io/api/serviceerror"

"github.com/formancehq/stack/libs/go-libs/logging"
Expand Down Expand Up @@ -60,10 +61,6 @@ func handleMessage(logger logging.Logger, temporalClient client.Client, taskQueu
if err != nil {
return err
}
// todo: debug
if event.Type != "SAVED_PAYMENT" {
return nil
}

logger = logger.WithField("type", event.Type)

Expand Down
12 changes: 10 additions & 2 deletions components/payments/internal/app/messages/payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ type paymentMessagePayload struct {
Asset models.Asset `json:"asset"`

// TODO: Remove 'initialAmount' once frontend has switched to 'amount
InitialAmount *big.Int `json:"initialAmount"`
Amount *big.Int `json:"amount"`
InitialAmount *big.Int `json:"initialAmount"`
Amount *big.Int `json:"amount"`
Metadata map[string]string `json:"metadata"`
}

func NewEventSavedPayments(payment *models.Payment, provider models.ConnectorProvider) events.EventMessage {
Expand All @@ -35,6 +36,13 @@ func NewEventSavedPayments(payment *models.Payment, provider models.ConnectorPro
CreatedAt: payment.CreatedAt,
Amount: payment.Amount,
Provider: provider.String(),
Metadata: func() map[string]string {
ret := make(map[string]string)
for _, m := range payment.Metadata {
ret[m.Key] = m.Value
}
return ret
}(),
}

return events.EventMessage{
Expand Down

0 comments on commit bd45537

Please sign in to comment.