Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(webhook): Always dispatch webhook job #2297

Merged
merged 2 commits into from
Jul 23, 2024

Conversation

julienbourdeau
Copy link
Contributor

Description

Currently, we often make a query to the DB to figure if we should enqueue a job to send the webhooks.

As discussed during our tech meeting about a month ago, we're moving to always enqueuing a job. The job will simply do nothing if there is no webhook_endpoint configured for the given organization.

It doesn't show in the the diff but the orgs without endpoints won't receive any webhook.

current_organization.webhook_endpoints.each do |webhook_endpoint|
webhook = create_webhook(webhook_endpoint, payload)
SendHttpWebhookJob.perform_later(webhook)
end

Benefits

Down sides

  • Enqueues more jobs (very small jobs)

@julienbourdeau julienbourdeau self-assigned this Jul 17, 2024
@julienbourdeau julienbourdeau force-pushed the feat/webhook-always-enqueue branch from dd4684b to 22f437e Compare July 17, 2024 09:27
Copy link
Collaborator

@vincent-pochet vincent-pochet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@julienbourdeau julienbourdeau force-pushed the feat/webhook-always-enqueue branch from 22f437e to 30b6430 Compare July 23, 2024 11:47
@julienbourdeau julienbourdeau merged commit d4d934c into main Jul 23, 2024
6 checks passed
@julienbourdeau julienbourdeau deleted the feat/webhook-always-enqueue branch July 23, 2024 12:00
abdussamadbello pushed a commit to abdussamadbello/lago-api that referenced this pull request Aug 8, 2024
## Description

Currently, we often make a query to the DB to figure if we should
enqueue a job to send the webhooks.

As discussed during our tech meeting about a month ago, we're moving to
always enqueuing a job. The job will simply do nothing if there is no
webhook_endpoint configured for the given organization.

It doesn't show in the the diff but the orgs without endpoints won't
receive any webhook.


https://github.com/getlago/lago-api/blob/b615f63a405efe81990436667f99c6ee34b408e6/app/services/webhooks/base_service.rb#L24-L27

### Benefits

* Centralized logic of _"should we send webhook?"_ in the job (easier if
want to [subscribe to only a subset of
webhooks](getlago#1993))
* Saves a query during the main tasks

### Down sides

* Enqueues more jobs (very small jobs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants