Skip to content

Commit 7239764

Browse files
committed
Merge pull request #169 from just3ws/activate_pending_users
Fixed a bug where the job would be enqueued ~58 hours in the future
2 parents afa070d + 3ef8fc8 commit 7239764

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

app/workers/activate_pending_users_worker.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@ class ActivatePendingUsersWorker
22
include Sidekiq::Worker
33
sidekiq_options queue: :critical
44

5-
65
def perform
76
# Spawning possibly many thousands
87
# of workers the order doesn't really matter
98
# but would like to spread their execution
109
# over the next hour to avoid overloading
1110
# the database.
12-
delay = 0
1311
User.pending.find_each(batch_size: 100) do |user|
14-
UserActivateWorker.perform_in(delay.minutes, user.id)
15-
delay = delay + Random.rand(0..59)
12+
UserActivateWorker.perform_in(Random.rand(0..59).minutes, user.id)
1613
end
1714
end
1815
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require 'sidekiq/testing'
2+
Sidekiq::Testing.inline!
3+
4+
RSpec.describe ActivatePendingUsersWorker do
5+
end

spec/workers/user_activate_worker_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
it 'should activate user' do
1919
worker.perform(user.id)
2020
user.reload
21-
21+
2222
expect(user.active?).to eq(true)
2323
expect(user.activated_on).not_to eq(nil)
2424
end
@@ -30,7 +30,7 @@
3030
it 'should do nothing' do
3131
worker.perform(user.id)
3232
user.reload
33-
33+
3434
expect(user.updated_at).to eq(user.created_at)
3535
end
3636
end

0 commit comments

Comments
 (0)