Reputation: 4142
Im running some backround jobs using delayed_job, and I wonder how I can retrive how long the job took to process
the information is displayed on the server, but I don't know how I can save it in order 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)
Upvotes: 3
Views: 758
Reputation: 500
In DJ 2.1, jobs can define before and after hooks. You could use these to record start and finish times in a database.
class ParanoidNewsletterJob < NewsletterJob
def before(job)
record_start job
end
def after(job)
record_finish job
end
...
end
Upvotes: 0
Reputation: 3304
Since the Delayed Job is deleted from your database upon completion, the simplest way to do it is to have the job itself make a record in your database when it starts, and then set the completed time in your callback when the job is completed. It's inelegant, but easy to implement with an existing system.
Upvotes: 2