diff --git a/app/models/scheduler_stat.rb b/app/models/scheduler_stat.rb index 55dc8fda6ac..258a437f647 100644 --- a/app/models/scheduler_stat.rb +++ b/app/models/scheduler_stat.rb @@ -17,4 +17,5 @@ end # live_slots_finish :integer # started_at :datetime not null # success :boolean +# error :text # diff --git a/db/migrate/20170425172415_add_error_to_scheduler_stats.rb b/db/migrate/20170425172415_add_error_to_scheduler_stats.rb new file mode 100644 index 00000000000..9d26ec29d74 --- /dev/null +++ b/db/migrate/20170425172415_add_error_to_scheduler_stats.rb @@ -0,0 +1,5 @@ +class AddErrorToSchedulerStats < ActiveRecord::Migration + def change + add_column :scheduler_stats, :error, :text + end +end diff --git a/lib/scheduler/manager.rb b/lib/scheduler/manager.rb index 1846aa7669a..44317f7cc65 100644 --- a/lib/scheduler/manager.rb +++ b/lib/scheduler/manager.rb @@ -78,6 +78,8 @@ module Scheduler start = Time.now.to_f info = @mutex.synchronize { @manager.schedule_info(klass) } stat = nil + error = nil + begin info.prev_result = "RUNNING" @mutex.synchronize { info.write! } @@ -96,6 +98,7 @@ module Scheduler failed = true rescue => e Discourse.handle_job_exception(e, {message: "Running a scheduled job", job: klass}) + error = "#{e.message}: #{e.backtrace.join("\n")}" failed = true end duration = ((Time.now.to_f - start) * 1000).to_i @@ -103,10 +106,11 @@ module Scheduler info.prev_result = failed ? "FAILED" : "OK" info.current_owner = nil if stat - stat.update_columns( + stat.update!( duration_ms: duration, live_slots_finish: GC.stat[:heap_live_slots], - success: !failed + success: !failed, + error: error ) end attempts(3) do