Last active
March 31, 2022 19:14
-
-
Save nroose/68a8c2eb2ac7c541154043b8d41fcbcf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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