Class: GoodJob::JobPerformer
- Inherits:
-
Object
- Object
- GoodJob::JobPerformer
- Defined in:
- lib/good_job/job_performer.rb
Overview
Instance Method Summary collapse
-
#initialize(queue_string) ⇒ JobPerformer
constructor
A new instance of JobPerformer.
-
#name ⇒ String
A meaningful name to identify the performer in logs and for debugging.
-
#next ⇒ Object?
Perform the next eligible job.
-
#next?(state = {}) ⇒ Boolean
Tests whether this performer should be used in GoodJob’s current state.
-
#next_at(after: nil, limit: nil, now_limit: nil) ⇒ Array<DateTime, Time>?
The Returns timestamps of when next tasks may be available.
Constructor Details
#initialize(queue_string) ⇒ JobPerformer
Returns a new instance of JobPerformer.
14 15 16 17 18 19 |
# File 'lib/good_job/job_performer.rb', line 14 def initialize(queue_string) @queue_string = queue_string @job_query = Concurrent::Delay.new { GoodJob::Job.queue_string(queue_string) } @parsed_queues = Concurrent::Delay.new { GoodJob::Job.queue_parser(queue_string) } end |
Instance Method Details
#name ⇒ String
A meaningful name to identify the performer in logs and for debugging.
23 24 25 |
# File 'lib/good_job/job_performer.rb', line 23 def name @queue_string end |
#next ⇒ Object?
Perform the next eligible job
29 30 31 |
# File 'lib/good_job/job_performer.rb', line 29 def next job_query.perform_with_advisory_lock end |
#next?(state = {}) ⇒ Boolean
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.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/good_job/job_performer.rb', line 42 def next?(state = {}) return true unless state[:queue_name] if parsed_queues[:exclude] parsed_queues[:exclude].exclude?(state[:queue_name]) elsif parsed_queues[:include] parsed_queues[:include].include?(state[:queue_name]) else true end end |
#next_at(after: nil, limit: nil, now_limit: nil) ⇒ Array<DateTime, Time>?
The Returns timestamps of when next tasks may be available.
59 60 61 |
# File 'lib/good_job/job_performer.rb', line 59 def next_at(after: nil, limit: nil, now_limit: nil) job_query.next_scheduled_at(after: after, limit: limit, now_limit: now_limit) end |