Applied rubocop cop 'Style/RedundantBegin'.
This commit is contained in:
parent
4c0fa5111d
commit
bc6a8ca169
1 changed files with 24 additions and 26 deletions
|
@ -82,37 +82,35 @@ 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 )
|
||||||
|
job.last_run = Time.zone.now
|
||||||
|
job.pid = Thread.current.object_id
|
||||||
|
job.save
|
||||||
|
logger.info "execute #{job.method} (try_count #{try_count})..."
|
||||||
|
eval job.method() # rubocop:disable Lint/Eval
|
||||||
|
rescue => e
|
||||||
|
logger.error "execute #{job.method} (try_count #{try_count}) exited with error #{e.inspect}"
|
||||||
|
|
||||||
|
# reconnect in case db connection is lost
|
||||||
begin
|
begin
|
||||||
job.last_run = Time.zone.now
|
ActiveRecord::Base.connection.reconnect!
|
||||||
job.pid = Thread.current.object_id
|
|
||||||
job.save
|
|
||||||
logger.info "execute #{job.method} (try_count #{try_count})..."
|
|
||||||
eval job.method() # rubocop:disable Lint/Eval
|
|
||||||
rescue => e
|
rescue => e
|
||||||
logger.error "execute #{job.method} (try_count #{try_count}) exited with error #{e.inspect}"
|
logger.error "Can't reconnect to database #{e.inspect}"
|
||||||
|
end
|
||||||
|
|
||||||
# reconnect in case db connection is lost
|
try_run_max = 10
|
||||||
begin
|
try_count += 1
|
||||||
ActiveRecord::Base.connection.reconnect!
|
|
||||||
rescue => e
|
|
||||||
logger.error "Can't reconnect to database #{e.inspect}"
|
|
||||||
end
|
|
||||||
|
|
||||||
try_run_max = 10
|
# reset error counter if to old
|
||||||
try_count += 1
|
if try_run_time + ( 60 * 5 ) < Time.zone.now
|
||||||
|
try_count = 0
|
||||||
|
end
|
||||||
|
try_run_time = Time.zone.now
|
||||||
|
|
||||||
# reset error counter if to old
|
# restart job again
|
||||||
if try_run_time + ( 60 * 5 ) < Time.zone.now
|
if try_run_max > try_count
|
||||||
try_count = 0
|
_start_job( job, try_count, try_run_time)
|
||||||
end
|
else
|
||||||
try_run_time = Time.zone.now
|
raise "STOP thread for #{job.method} after #{try_count} tries"
|
||||||
|
|
||||||
# restart job again
|
|
||||||
if try_run_max > try_count
|
|
||||||
_start_job( job, try_count, try_run_time)
|
|
||||||
else
|
|
||||||
raise "STOP thread for #{job.method} after #{try_count} tries"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue