* feat: add an error column to the data update script * feat: save the error to the error field * feat: save the error when the script fails * feat: show the script error on the data update script page * chore: pass the error to mark_as_failed instead of having its own function * refactor: use presence * test: ensure that we test an error case of a data update script * chore: rename errorneous to failing * test: update some specs, working on the others * chore: update tests now that there are two files * chore: change error from a string to a text to allow for more char
42 lines
980 B
Ruby
42 lines
980 B
Ruby
class DataUpdateWorker
|
|
include Sidekiq::Worker
|
|
sidekiq_options queue: :high_priority, retry: 5
|
|
|
|
def perform
|
|
DataUpdateScript.scripts_to_run.each do |script|
|
|
script.mark_as_run!
|
|
log_status(script)
|
|
|
|
run_script(script)
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def run_script(script)
|
|
require script.file_path
|
|
|
|
script.file_class.new.run
|
|
|
|
script.mark_as_finished!
|
|
log_status(script)
|
|
rescue StandardError => e
|
|
script.mark_as_failed!(e)
|
|
log_status(script)
|
|
|
|
Honeybadger.notify(e, context: { script_id: script.id })
|
|
end
|
|
|
|
def log_status(script)
|
|
status = script.status
|
|
file_name = script.file_name
|
|
|
|
logger_destination = status.to_sym == :failed ? :error : :info
|
|
Rails.logger.public_send(
|
|
logger_destination,
|
|
"time=#{Time.current.rfc3339}, script=#{file_name}, status=#{status}",
|
|
)
|
|
|
|
DatadogStatsClient.increment("data_update_scripts.status", tags: ["status:#{status}", "script_name:#{file_name}"])
|
|
end
|
|
end
|