Skip to content

Commit

Permalink
feat(refresh-credits): Add job to refresh wallets credits
Browse files Browse the repository at this point in the history
  • Loading branch information
rsempe committed Jan 16, 2024
1 parent 779d03e commit 730a7b2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/jobs/clock/refresh_wallets_credits_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Clock
class RefreshWalletsCreditsJob < ApplicationJob
queue_as 'clock'

def perform
Wallet.active.find_each do |wallet|
Wallets::RefreshCreditsJob.perform_later(wallet)
end
end
end
end
4 changes: 4 additions & 0 deletions clock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ module Clockwork
Clock::RefreshDraftInvoicesJob.perform_later
end

every(5.minutes, 'schedule:refresh_wallets_credits') do
Clock::RefreshWalletsCreditsJob.perform_later
end

every(1.hour, 'schedule:terminate_ended_subscriptions', at: '*:05') do
Clock::TerminateEndedSubscriptionsJob.perform_later
end
Expand Down
30 changes: 30 additions & 0 deletions spec/jobs/clock/refresh_wallets_credits_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

require 'rails_helper'

describe Clock::RefreshWalletsCreditsJob, job: true do
subject { described_class }

describe '.perform' do
let(:wallet) { create(:wallet) }

before do
wallet
allow(Wallets::RefreshCreditsService).to receive(:call)
end

it 'calls the refresh service' do
described_class.perform_now
expect(Wallets::RefreshCreditsJob).to have_been_enqueued.with(wallet)
end

context 'when not active' do
let(:wallet) { create(:wallet, :terminated) }

it 'does not call the refresh service' do
described_class.perform_now
expect(Wallets::RefreshCreditsJob).not_to have_been_enqueued.with(wallet)
end
end
end
end

0 comments on commit 730a7b2

Please sign in to comment.