mirror of
https://github.com/plashchynski/crono.git
synced 2026-03-28 12:22:04 +01:00
Handle a few jobs scheduled at the same time
This commit is contained in:
@@ -79,9 +79,10 @@ module Crono
|
||||
end
|
||||
|
||||
def start_working_loop
|
||||
while (job = Crono.scheduler.next)
|
||||
sleep(job.next - Time.now)
|
||||
job.perform
|
||||
while true
|
||||
next_time, jobs = Crono.scheduler.next_jobs
|
||||
sleep(next_time - Time.now)
|
||||
jobs.each(&:perform)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -17,8 +17,7 @@ module Crono
|
||||
end
|
||||
|
||||
def next
|
||||
next_time = period.next(since: last_performed_at)
|
||||
next_time.past? ? period.next : next_time
|
||||
period.next(since: last_performed_at)
|
||||
end
|
||||
|
||||
def description
|
||||
|
||||
@@ -12,14 +12,8 @@ module Crono
|
||||
jobs << job
|
||||
end
|
||||
|
||||
def next
|
||||
queue.first
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def queue
|
||||
jobs.sort_by(&:next)
|
||||
def next_jobs
|
||||
jobs.group_by(&:next).sort_by {|time,_| time }.first
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user