How to get delayed work time?

I am running several background jobs using delayed_job, and I am wondering how I can get how much time it took to process

information is displayed on the server, but I do not know how I can save it to use it in my controllers / views

Delayed::Backend::ActiveRecord::Job Load (0.8ms)  SELECT "delayed_jobs".* FROM "delayed_jobs" WHERE ("delayed_jobs"."id" = 83) LIMIT 1
Completed 200 OK in 9ms (Views: 6.8ms | ActiveRecord: 0.8ms)
  AREL (0.4ms)  DELETE FROM "delayed_jobs" WHERE ("delayed_jobs"."id" = 83)
+3
source share
2 answers

Since Job Delay is removed from your database at the end, the easiest way to do this is to get the job to write to your database yourself when it starts, and then set the completed time in your callback when the job is completed. It is inelegant, but easily implemented with the existing system.

+2
source

DJ 2.1 . .

class ParanoidNewsletterJob < NewsletterJob
  def before(job)
    record_start job
  end

  def after(job)
    record_finish job
  end
...
end
0

Source: https://habr.com/ru/post/1788025/


All Articles