Class: Delayed::Backend::ActiveRecord::Job

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/dj_split/dj_activerecord_overrides.rb

Class Method Summary collapse

Class Method Details

.reserve(worker, max_run_time = Worker.max_run_time) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dj_split/dj_activerecord_overrides.rb', line 5

def self.reserve(worker, max_run_time = Worker.max_run_time)
  # scope to filter to records that are "ready to run"
  ready_scope = ready_to_run(worker.name, max_run_time)

  # scope to filter to the single next eligible job
  ready_scope = ready_scope.where("priority >= ?", Worker.min_priority) if Worker.min_priority
  ready_scope = ready_scope.where("priority <= ?", Worker.max_priority) if Worker.max_priority
  unless worker.split_group_id
    ready_scope = ready_scope.where(queue: Worker.queues) if Worker.queues.any?
  end
  # filter only jobs with worker job group id
  ready_scope = ready_scope.where(split_group_id: worker.split_group_id) if worker.split_group_id
  ready_scope = ready_scope.by_priority

  reserve_with_scope(ready_scope, worker, db_time_now)
end