Skip to content

Commit

Permalink
Pubsub events (#37)
Browse files Browse the repository at this point in the history
* ps client

* print

* payload?

* topic name
  • Loading branch information
baely authored Aug 7, 2024
1 parent c3868fd commit 73ff18d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
25 changes: 25 additions & 0 deletions function.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,31 @@ func ProcessTransaction(w http.ResponseWriter, r *http.Request) {
}

wg.Wait()

// push the message to pubsub
type TransactionEvent struct {
Account model.AccountResource
Transaction model.TransactionResource
}

data, _ := json.Marshal(TransactionEvent{
Account: account,
Transaction: transaction,
})

client := integrations.GetClient()
topic := client.Topic("transactions")
res := topic.Publish(context.Background(), &pubsub.Message{
ID: uuid.NewString(),
Data: data,
})
id, err := res.Get(context.Background())
if err != nil {
fmt.Println("error publishing message:", err)
} else {
fmt.Println("new published message:", id)
}

return
}

Expand Down
1 change: 0 additions & 1 deletion internal/service/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func formatCurrency(value string, iso string) string {
}

func SendWebhookEvent(uri string, account model.AccountResource, transaction model.TransactionResource) error {

_, err := url.Parse(uri)
if err != nil {
return err
Expand Down

0 comments on commit 73ff18d

Please sign in to comment.