Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Scheduler#cache_warm on global thread pool instead of Scheduler's thread pool #311

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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