Small improvements.

This commit is contained in:
Martin Edenhofer 2015-07-01 00:26:02 +02:00
parent d73784e7fd
commit d685c8f264

View file

@ -26,7 +26,7 @@ class Scheduler < ApplicationModel
end end
# read/load jobs and check if it is alredy started # read/load jobs and check if it is alredy started
jobs = Scheduler.where( 'active = ?', true ) jobs = Scheduler.where( 'active = ?', true ).order('prio ASC')
jobs.each {|job| jobs.each {|job|
# ignore job is still running # ignore job is still running
@ -37,14 +37,14 @@ class Scheduler < ApplicationModel
# run job as own thread # run job as own thread
@@jobs_started[ job.id ] = true @@jobs_started[ job.id ] = true
start_job( job ) start_job(job)
sleep 10
} }
sleep 60 sleep 60
end end
end end
def self.start_job( job ) def self.start_job( job )
sleep 4
Thread.new { Thread.new {
@ -53,8 +53,8 @@ class Scheduler < ApplicationModel
# start loop for periods under 5 minutes # start loop for periods under 5 minutes
if job.period && job.period <= 300 if job.period && job.period <= 300
loop do loop do
_start_job( job ) _start_job(job)
job = Scheduler.lookup( id: job.id ) job = Scheduler.lookup(id: job.id)
# exit is job got deleted # exit is job got deleted
break if !job break if !job
@ -69,7 +69,7 @@ class Scheduler < ApplicationModel
sleep job.period sleep job.period
end end
else else
_start_job( job ) _start_job(job)
end end
job.pid = '' job.pid = ''
job.save job.save
@ -82,7 +82,6 @@ class Scheduler < ApplicationModel
end end
def self._start_job( job, try_count = 0, try_run_time = Time.zone.now ) def self._start_job( job, try_count = 0, try_run_time = Time.zone.now )
sleep 5
begin begin
job.last_run = Time.zone.now job.last_run = Time.zone.now
job.pid = Thread.current.object_id job.pid = Thread.current.object_id