diff --git a/app/workers/activate_pending_users_worker.rb b/app/workers/activate_pending_users_worker.rb index 0f0ef3c1..5010ffaa 100644 --- a/app/workers/activate_pending_users_worker.rb +++ b/app/workers/activate_pending_users_worker.rb @@ -2,17 +2,14 @@ class ActivatePendingUsersWorker include Sidekiq::Worker sidekiq_options queue: :critical - def perform # Spawning possibly many thousands # of workers the order doesn't really matter # but would like to spread their execution # over the next hour to avoid overloading # the database. - delay = 0 User.pending.find_each(batch_size: 100) do |user| - UserActivateWorker.perform_in(delay.minutes, user.id) - delay = delay + Random.rand(0..59) + UserActivateWorker.perform_in(Random.rand(0..59).minutes, user.id) end end end diff --git a/spec/workers/activate_pending_users_worker_spec.rb b/spec/workers/activate_pending_users_worker_spec.rb new file mode 100644 index 00000000..c009fd5f --- /dev/null +++ b/spec/workers/activate_pending_users_worker_spec.rb @@ -0,0 +1,5 @@ +require 'sidekiq/testing' +Sidekiq::Testing.inline! + +RSpec.describe ActivatePendingUsersWorker do +end diff --git a/spec/workers/user_activate_worker_spec.rb b/spec/workers/user_activate_worker_spec.rb index 525c9a08..6f17dcf3 100644 --- a/spec/workers/user_activate_worker_spec.rb +++ b/spec/workers/user_activate_worker_spec.rb @@ -18,7 +18,7 @@ it 'should activate user' do worker.perform(user.id) user.reload - + expect(user.active?).to eq(true) expect(user.activated_on).not_to eq(nil) end @@ -30,7 +30,7 @@ it 'should do nothing' do worker.perform(user.id) user.reload - + expect(user.updated_at).to eq(user.created_at) end end