-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add clock job to clean old (older than 90 days) inbound webhooks from DB
- Loading branch information
Showing
4 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module Clock | ||
class InboundWebhooksCleanupJob < ApplicationJob | ||
include SentryCronConcern | ||
|
||
queue_as 'clock' | ||
|
||
def perform | ||
InboundWebhook.where('updated_at < ?', 90.days.ago).destroy_all | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
describe Clock::InboundWebhooksCleanupJob, job: true do | ||
subject(:inbound_webhooks_cleanup_job) { described_class } | ||
|
||
describe ".perform" do | ||
it "removes all old inbound webhooks" do | ||
create(:inbound_webhook, updated_at: 90.days.ago) | ||
|
||
expect { inbound_webhooks_cleanup_job.perform_now } | ||
.to change(InboundWebhook, :count).to(0) | ||
end | ||
|
||
it "does not delete recent inbound webhooks" do | ||
create(:inbound_webhook, updated_at: 89.days.ago) | ||
|
||
expect { inbound_webhooks_cleanup_job.perform_now } | ||
.not_to change(InboundWebhook, :count) | ||
end | ||
end | ||
end |