Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Base instrumentation for ActiveJob + Sidekiq
def stats
# TODO
end
def dogtags
# TODO
end
ActiveSupport::Notifications.subscribe("enqueue.active_job") do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
job = event.payload.fetch(:job)
job_name = job.class.name.underscore
queue_name = job.queue_name
depth = Sidekiq::Queue.new(queue_name)
stats.increment("job.enqueued", {
tags: dogtags(job: job_name, queue: queue_name),
})
stats.gauge("job.depth", depth, {
tags: dogtags(queue: queue_name),
})
end
ActiveSupport::Notifications.subscribe("enqueue_at.active_job") do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
job = event.payload.fetch(:job)
job_name = job.class.name.underscore
queue_name = job.queue_name
depth = Sidekiq::Queue.new(queue_name)
stats.increment("job.scheduled", {
tags: dogtags(job: job_name, queue: queue_name),
})
stats.gauge("job.depth", depth, {
tags: dogtags(queue: queue_name),
})
end
ActiveSupport::Notifications.subscribe("perform.active_job") do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
job = event.payload.fetch(:job)
job_name = job.class.name.underscore
queue_name = job.queue_name
depth = Sidekiq::Queue.new(queue_name)
stats.timing("job.time", event.duration, {
tags: dogtags(job: job_name, queue: queue_name),
})
stats.gauge("job.depth", depth, {
tags: dogtags(queue: queue_name),
})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.