Skip to content

Commit

Permalink
Add support for LAGO_LIFETIME_USAGE_REFRESH_INTERVAL_SECONDS
Browse files Browse the repository at this point in the history
  • Loading branch information
nudded committed Aug 22, 2024
1 parent 681bdfa commit 81f4be7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
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

0 comments on commit 81f4be7

Please sign in to comment.