I’ve got a delayed job running and I want to saved the runtime when it finishes, the worker logs the runtime to the logs like this…
XXXXXJob completed after 1.6372
I was wondering how you access this statistic from inside the delayed job class?
I’ve tried self.runtime but that’s throwing an error.
Cheers.
I’m afraid
delayed_jobgem doesn’t provide API for accessing that stats. Looks like here is the place were they calculate running time and that’s what is happening there:So
runtimeis calculated usingBenchmarkmodule and logged, but it’s not stored anywhere for later usage.Though, you still can calculate runtime of the job yourself by wrapping its logic with similar
Benchmark.realtimecall or something like that.