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

Purge Outgoing Webhooks events and deliveries data #229

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Webhooks::Outgoing::PurgeJob < ApplicationJob
queue_as :default

def perform(days_old = 90)
# Delete children first, then parents.
purge(Webhooks::Outgoing::DeliveryAttempt, days_old)
purge(Webhooks::Outgoing::Delivery, days_old)
purge(Webhooks::Outgoing::Event, days_old)
end

def purge(model, days_old)
model.where("created_at < ?", days_old.days.ago).delete_all
end
end
2 changes: 2 additions & 0 deletions bullet_train/docs/webhooks/outgoing.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ payment.generate_webhook(:succeeded)
## Delivery
Webhooks are delivered asyncronously in a background job by default. If the resulting HTTP request results in a status code other than those in the 2XX series, it will be considered a failed attempt and delivery will be reattempted a number of times.

All of the delivery attempts and events are stored in the database. There is a background job to purge records in these tables as they can grow large in size over time. You can schedule this job to purge records older than 90 days by default.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add an example of at least how to call the job here, just so people don't have to go hunting for it?

## Future Plans
- Allow users to filter webhooks to be generated by a given parent model. For example, they should be able to subscribe to `post.created`, but only for `Post` objects created within a certain `Project`.
- Integrate [Hammerstone Refine](https://hammerstone.dev) to allow even greater configurability for filtering webhooks.