Skip to content

Commit

Permalink
feat(dunning): schedule process dunning campaigns jobs every hour at 45'
Browse files Browse the repository at this point in the history
 ## Roadmap Task

πŸ‘‰ https://getlago.canny.io/feature-requests/p/set-up-payment-retry-logic
πŸ‘‰
https://getlago.canny.io/feature-requests/p/send-reminders-for-overdue-invoices

 ## Context

We want to automate dunning process so that our users don't have to look
at each customer to maximize their chances of being paid retrying
payments of overdue balances and sending email reminders.

We're first automating the overdue balance payment request, before
looking at individual invoices.

 ## Description

This change adds the scheduler to run the ProcessDunningCampaigns job
every hour at 45 minute.
  • Loading branch information
ancorcruz committed Oct 31, 2024
1 parent 90accd3 commit b0e0188
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions clock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,10 @@ module Clockwork
.set(sentry: {"slug" => 'lago_compute_daily_usage', "cron" => '15 */1 * * *'})
.perform_later
end

every(1.hour, "schedule:process_dunning_campaigns", at: "*:45") do
Clock::ProcessDunningCampaignsJob
.set(sentry: {"slug" => "lago_process_dunning_campaigns", "cron" => "45 */1 * * *"})
.perform_later
end
end
21 changes: 21 additions & 0 deletions spec/clockwork_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,25 @@
expect(Clock::ComputeAllDailyUsagesJob).to have_been_enqueued
end
end

describe "schedule:process_dunning_campaigns" do
let(:job) { "schedule:process_dunning_campaigns" }
let(:start_time) { Time.zone.parse("1 Apr 2022 00:01:00") }
let(:end_time) { Time.zone.parse("1 Apr 2022 01:01:00") }

it "enqueue a process dunning campaigns job" do
Clockwork::Test.run(
file: clock_file,
start_time:,
end_time:,
tick_speed: 1.second
)

expect(Clockwork::Test).to be_ran_job(job)
expect(Clockwork::Test.times_run(job)).to eq(1)

Clockwork::Test.block_for(job).call
expect(Clock::ProcessDunningCampaignsJob).to have_been_enqueued
end
end
end

0 comments on commit b0e0188

Please sign in to comment.