Improved codestyle.

This commit is contained in:
Rolf Schmidt 2017-09-07 15:00:12 +02:00
parent 7b86174d26
commit d3e4577fa5
2 changed files with 18 additions and 17 deletions

View file

@ -81,9 +81,9 @@ curl http://localhost/api/v1/monitoring/health_check?token=XXX
issues.push 'scheduler not running' issues.push 'scheduler not running'
end end
Scheduler.where(status: 'error').each { |scheduler| Scheduler.where(status: 'error').each do |scheduler|
issues.push "Failed to run scheduled job \'#{scheduler.name}\'. Cause: #{scheduler.error_message}" issues.push "Failed to run scheduled job \'#{scheduler.name}\'. Cause: #{scheduler.error_message}"
} end
token = Setting.get('monitoring_token') token = Setting.get('monitoring_token')
@ -181,16 +181,14 @@ curl http://localhost/api/v1/monitoring/status?token=XXX
access_check access_check
count = 0 count = 0
Scheduler.where(status: 'error').where(active: false).each { |scheduler| Scheduler.where(status: 'error', active: false).each do |scheduler|
scheduler.active = true scheduler.update(active: true)
scheduler.save
count += 1 count += 1
} end
result = { render json: {
job_restart_count: count job_restart_count: count
} }
render json: result
end end
private private

View file

@ -169,11 +169,13 @@ 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.update(
job.pid = Thread.current.object_id last_run: Time.zone.now,
job.status = 'ok' pid: Thread.current.object_id,
job.error_message = '' status: 'ok',
job.save error_message: '',
)
logger.info "execute #{job.method} (try_count #{try_count})..." logger.info "execute #{job.method} (try_count #{try_count})..."
eval job.method() # rubocop:disable Lint/Eval eval job.method() # rubocop:disable Lint/Eval
rescue => e rescue => e
@ -203,10 +205,11 @@ class Scheduler < ApplicationModel
error = "Failed to run #{job.method} after #{try_count} tries #{e.inspect}" error = "Failed to run #{job.method} after #{try_count} tries #{e.inspect}"
logger.error error logger.error error
job.error_message = error job.update(
job.status = 'error' error_message: error,
job.active = false status: 'error',
job.save active: false,
)
end end
end end