Skip to content

Commit

Permalink
Run Scheduler#cache_warm on global thread pool instead of Scheduler's…
Browse files Browse the repository at this point in the history
… thread pool
  • Loading branch information
bensheldon committed Jul 26, 2021
1 parent a870c99 commit 66be388
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/good_job/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,15 @@ def stats
# Preload existing runnable and future-scheduled jobs
# @return [void]
def warm_cache
return if @max_cache.zero?
return unless @max_cache.positive?

future = Concurrent::Future.new(args: [self, @performer, @max_cache, @executor_options[:max_threads]]) do |thr_scheduler, thr_performer, thr_max_cache, thr_max_threads|
return unless thr_scheduler.running?

future = Concurrent::Future.new(args: [self, @performer], executor: executor) do |thr_scheduler, thr_performer|
Rails.application.executor.wrap do
thr_performer.next_at(
limit: @max_cache,
now_limit: @executor_options[:max_threads]
limit: thr_max_cache,
now_limit: thr_max_threads
).each do |scheduled_at|
thr_scheduler.create_thread({ scheduled_at: scheduled_at })
end
Expand All @@ -205,7 +207,6 @@ def warm_cache

observer = lambda do |_time, _output, thread_error|
GoodJob.on_thread_error.call(thread_error) if thread_error && GoodJob.on_thread_error.respond_to?(:call)
create_task # If cache-warming exhausts the threads, ensure there isn't an executable task remaining
end
future.add_observer(observer, :call)

Expand Down

0 comments on commit 66be388

Please sign in to comment.