Skip to content

Instantly share code, notes, and snippets.

@nroose
Last active March 31, 2022 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nroose/68a8c2eb2ac7c541154043b8d41fcbcf to your computer and use it in GitHub Desktop.
Save nroose/68a8c2eb2ac7c541154043b8d41fcbcf to your computer and use it in GitHub Desktop.
# Add info in the ps listing of rails server and delayed jobs processes
# app/controllers/application_controller.rb
before_action :proctitle
after_action :unproctitle
def proctitle
path = request.env['REQUEST_PATH']&.first(25)
Process.setproctitle("#{$PROGRAM_NAME} - #{path}")
end
def unproctitle
Process.setproctitle($PROGRAM_NAME)
end
# config/initializers/delayed_job
require 'delayed_job'
class ProctitleDelayedPlugin < Delayed::Plugin
callbacks do |lifecycle|
lifecycle.around(:invoke_job) do |job, *args, &block|
Process.setproctitle("#{$PROGRAM_NAME} #{job.id} #{job.name.split.first} #{job.attempts.ordinalize}")
block.call(job, *args)
Process.setproctitle($PROGRAM_NAME)
end
end
end
Delayed::Worker.plugins << ProctitleDelayedPlugin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment