SendWebhook enqueues a webhook notification task using the LedgerForge instance's asynq client. Parameters: - newWebhook NewWebhook: The webhook notification data to enqueue. Returns: - error: An error if the task could not be enqueued.
(newWebhook NewWebhook)
| 131 | // Returns: |
| 132 | // - error: An error if the task could not be enqueued. |
| 133 | func (b *LedgerForge) SendWebhook(newWebhook NewWebhook) error { |
| 134 | conf := b.Config() |
| 135 | |
| 136 | if conf.Notification.Webhook.Url == "" { |
| 137 | return nil |
| 138 | } |
| 139 | |
| 140 | payload, err := json.Marshal(newWebhook) |
| 141 | if err != nil { |
| 142 | return err |
| 143 | } |
| 144 | taskOptions := []asynq.Option{asynq.Queue(conf.Queue.WebhookQueue)} |
| 145 | task := asynq.NewTask(conf.Queue.WebhookQueue, payload, taskOptions...) |
| 146 | info, err := b.asynqClient.Enqueue(task) |
| 147 | if err != nil { |
| 148 | logrus.Error(err, info) |
| 149 | return err |
| 150 | } |
| 151 | return err |
| 152 | } |
| 153 | |
| 154 | // ProcessWebhook processes a webhook notification task from the queue. |
| 155 | // |