Class: Schedule

Inherits:
Object
  • Object
show all
Defined in:
app/models/schedule.rb

Class Method Summary collapse

Class Method Details

.available_slotsObject


28
29
30
31
32
33
34
35
# File 'app/models/schedule.rb', line 28

def available_slots
  sum = 0
  Host.all.each do |h|
    h.update_status
    sum += h.available_slots
  end
  sum
end

.run!Object


3
4
5
6
# File 'app/models/schedule.rb', line 3

def run!
  processed = update_jobs + schedule_jobs
  processed.size
end

.schedule_jobsObject


14
15
16
17
18
# File 'app/models/schedule.rb', line 14

def schedule_jobs
  to_be_scheduled_jobs.each do |job|
    job.with_lock(true) { schedule_job(job) }
  end
end

.to_be_scheduled_jobsObject


24
25
26
# File 'app/models/schedule.rb', line 24

def to_be_scheduled_jobs
  Job.where(state: [Job::Scheduled]).order('created_at').limit(available_slots)
end

.to_be_updated_jobsObject


20
21
22
# File 'app/models/schedule.rb', line 20

def to_be_updated_jobs
  Job.where(state: [Job::Processing, Job::OnHold]).order('created_at')
end

.update_jobsObject


8
9
10
11
12
# File 'app/models/schedule.rb', line 8

def update_jobs
  to_be_updated_jobs.each do |job|
    job.with_lock(true) { update_job(job) }
  end
end