Last active
October 1, 2021 06:57
-
-
Save michaelkl/558584100dad3c9158e07b9adff6eb9a to your computer and use it in GitHub Desktop.
DelayedJob log job queue time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Measures each job's time spent in a queue | |
# | |
# Register the pluging to start using it | |
# Delayed::Worker.plugins << Delayed::QueueTimeLoggerPlugin | |
# | |
class Delayed::QueueTimeLoggerPlugin < Delayed::Plugin | |
callbacks do |lifecycle| | |
lifecycle.before(:perform) do |worker, job| | |
queued_for = Time.zone.now - job.created_at | |
worker.job_say job, | |
"invoked after queuing for #{queued_for.truncate(1)} s "\ | |
"(attempts #{job.attempts})" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment