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'
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}"
}
end
token = Setting.get('monitoring_token')
@ -181,16 +181,14 @@ curl http://localhost/api/v1/monitoring/status?token=XXX
access_check
count = 0
Scheduler.where(status: 'error').where(active: false).each { |scheduler|
scheduler.active = true
scheduler.save
Scheduler.where(status: 'error', active: false).each do |scheduler|
scheduler.update(active: true)
count += 1
}
end
result = {
render json: {
job_restart_count: count
}
render json: result
end
private

View file

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