Skip to content

Instantly share code, notes, and snippets.

@michaelkl
Last active October 1, 2021 06:57
Show Gist options
  • Save michaelkl/558584100dad3c9158e07b9adff6eb9a to your computer and use it in GitHub Desktop.
Save michaelkl/558584100dad3c9158e07b9adff6eb9a to your computer and use it in GitHub Desktop.
DelayedJob log job queue time
# 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