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(ProgressiveBilling) - Add support for LAGO_LIFETIME_USAGE_REFRESH_INTERVAL_SECONDS #2460

Merged
merged 1 commit into from
Aug 22, 2024
Merged
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
5 changes: 3 additions & 2 deletions clock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ module Clockwork
.perform_later
end

every(5.minutes, 'schedule:refresh_lifetime_usages') do
lifetime_usage_refresh_interval = ENV["LAGO_LIFETIME_USAGE_REFRESH_INTERVAL_SECONDS"].presence || 5.minutes
every(lifetime_usage_refresh_interval.to_i.seconds, 'schedule:refresh_lifetime_usages') do
Clock::RefreshLifetimeUsagesJob
.set(sentry: {"slug" => 'lago_refresh_lifetime_usages', "cron" => '*/5 * * * *'})
.set(sentry: {"slug" => 'lago_refresh_lifetime_usages', "cron" => "#{lifetime_usage_refresh_interval} interval"})
.perform_later
end

Expand Down
24 changes: 24 additions & 0 deletions spec/clockwork_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,29 @@
Clockwork::Test.block_for(job).call
expect(Clock::RefreshLifetimeUsagesJob).to have_been_enqueued
end

context "with a custom refresh interval configured" do
before do
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:[]).with('LAGO_LIFETIME_USAGE_REFRESH_INTERVAL_SECONDS').and_return('150')
end

it 'uses the ENV["LAGO_LIFETIME_USAGE_REFRESH_INTERVAL_SECONDS"] to set a custom period' 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(12)

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

expect(ENV).to have_received(:[]).with('LAGO_LIFETIME_USAGE_REFRESH_INTERVAL_SECONDS')
end
end
end
end