lib/good_job/scheduler.rb in good_job-1.1.0 vs lib/good_job/scheduler.rb in good_job-1.1.1
- old
+ new
@@ -20,9 +20,34 @@
fallback_policy: :discard,
}.freeze
cattr_reader :instances, default: [], instance_reader: false
+ def self.from_configuration(configuration)
+ schedulers = configuration.queue_string.split(';').map do |queue_string_and_max_threads|
+ queue_string, max_threads = queue_string_and_max_threads.split(':')
+ max_threads = (max_threads || configuration.max_threads).to_i
+
+ job_query = GoodJob::Job.queue_string(queue_string)
+ job_performer = GoodJob::Performer.new(job_query, :perform_with_advisory_lock, name: queue_string)
+
+ timer_options = {}
+ timer_options[:execution_interval] = configuration.poll_interval if configuration.poll_interval.positive?
+
+ pool_options = {
+ max_threads: max_threads,
+ }
+
+ GoodJob::Scheduler.new(job_performer, timer_options: timer_options, pool_options: pool_options)
+ end
+
+ if schedulers.size > 1
+ GoodJob::MultiScheduler.new(schedulers)
+ else
+ schedulers.first
+ end
+ end
+
def initialize(performer, timer_options: {}, pool_options: {})
raise ArgumentError, "Performer argument must implement #next" unless performer.respond_to?(:next)
self.class.instances << self