diff --git a/app/jobs/base.rb b/app/jobs/base.rb index 1f6839ad8d6..64add443a22 100644 --- a/app/jobs/base.rb +++ b/app/jobs/base.rb @@ -255,7 +255,12 @@ module Jobs Thread.new do while parent_thread.alive? && !finished Discourse.redis.without_namespace.expire(cluster_concurrency_redis_key, 120) - sleep 60 + + # Sleep for 60 seconds, but wake up every second to check if the job has been completed + 60.times do + break if finished + sleep 1 + end end end end diff --git a/spec/jobs/jobs_base_spec.rb b/spec/jobs/jobs_base_spec.rb index 0467758028c..b38097c0b51 100644 --- a/spec/jobs/jobs_base_spec.rb +++ b/spec/jobs/jobs_base_spec.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true RSpec.describe ::Jobs::Base do + use_redis_snapshotting + class GoodJob < ::Jobs::Base attr_accessor :count def execute(args) @@ -62,12 +64,11 @@ RSpec.describe ::Jobs::Base do wait_for { ConcurrentJob.running? } ConcurrentJob.new.perform({ "test" => 100 }) + expect(Sidekiq::Queues["default"].size).to eq(1) - expect(Sidekiq::Queues["default"][0]["args"][0]).to eq("test" => 100) - + ensure ConcurrentJob.stop! - thread.join end