class GoodJob::JobPerformer

JobPerformer queries the database for jobs and performs them on behalf of a {Scheduler}. It mainly functions as glue between a {Scheduler} and the jobs it should be executing.

The JobPerformer must be safe to execute across multiple threads.

Attributes

queue_string[R]

Public Class Methods

new(queue_string) click to toggle source

@param queue_string [String] Queues to execute jobs from

   # File lib/good_job/job_performer.rb
14 def initialize(queue_string)
15   @queue_string = queue_string
16 
17   @job_query = Concurrent::Delay.new { GoodJob::Job.queue_string(queue_string) }
18   @parsed_queues = Concurrent::Delay.new { GoodJob::Job.queue_parser(queue_string) }
19 end

Public Instance Methods

name() click to toggle source

A meaningful name to identify the performer in logs and for debugging. @return [String] The queues from which Jobs are worked

   # File lib/good_job/job_performer.rb
23 def name
24   @queue_string
25 end
next() click to toggle source

Perform the next eligible job @return [Object, nil] Returns job result or nil if no job was found

   # File lib/good_job/job_performer.rb
29 def next
30   job_query.perform_with_advisory_lock
31 end
next?(state = {}) click to toggle source

Tests whether this performer should be used in GoodJob's current state.

For example, state will be a LISTEN/NOTIFY message that is passed down from the Notifier to the Scheduler. The Scheduler is able to ask its performer “does this message relate to you?”, and if not, ignore it to minimize thread wake-ups, database queries, and thundering herds.

@return [Boolean] whether the performer's {#next} method should be

called in the current state.
   # File lib/good_job/job_performer.rb
42 def next?(state = {})
43   return true unless state[:queue_name]
44 
45   if parsed_queues[:exclude]
46     parsed_queues[:exclude].exclude?(state[:queue_name])
47   elsif parsed_queues[:include]
48     parsed_queues[:include].include?(state[:queue_name])
49   else
50     true
51   end
52 end
next_at(after: nil, limit: nil, now_limit: nil) click to toggle source

The Returns timestamps of when next tasks may be available. @param after [DateTime, Time, nil] future jobs scheduled after this time @param limit [Integer] number of future timestamps to return @param now_limit [Integer] number of past timestamps to return @return [Array<DateTime, Time>, nil]

   # File lib/good_job/job_performer.rb
59 def next_at(after: nil, limit: nil, now_limit: nil)
60   job_query.next_scheduled_at(after: after, limit: limit, now_limit: now_limit)
61 end

Private Instance Methods

job_query() click to toggle source
   # File lib/good_job/job_performer.rb
67 def job_query
68   @job_query.value
69 end
parsed_queues() click to toggle source
   # File lib/good_job/job_performer.rb
71 def parsed_queues
72   @parsed_queues.value
73 end