monogreen - Tank you very much !

Setting the program name with $0

Here’s a quick tip that might be useful: In Ruby, you can set the title of the current Ruby process by assigning a string to $0. At Travel IQ, we’ve found this especially useful for long-running rake tasks that clean up and massage our data at night. Some of those rake tasks were running very long – and we were scratching our heads as to what they might be doing.

So we simply set the program name in every rake task and its dependencies, and the next time around, a look at htop revealed where we’ve been stuck.

One caveat, though: It seems that on Ubuntu machines, the maximum length of the program name is determined when the process is started, i.e. setting it later to something longer truncates the new value to the length of the first: http://www.ruby-forum.com/topic/187083

Post a comment


(lesstile enabled - surround code blocks with ---)