5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/rearview/distribute.rb', line 5
def by_delay(jobs)
job_meta = jobs.map { |j| [j,{:delay=>j.delay,:initial_delay=>0}] }
job_meta.sort! { |a,b| a.last[:delay] <=> b.last[:delay] }
default_offset_amnt = 2.0
other_offset_amnt = 2.0
default_offset_count = 0
other_offset_count = 0
job_meta.each do |m|
if m.first.cron_expr == "0 * * * * ?"
m.last[:initial_delay] = default_offset_amnt * default_offset_count
default_offset_count+=1
else
m.last[:initial_delay] = other_offset_amnt * other_offset_count
other_offset_count+=1
end
end
job_meta
end
|