Ruby rbtrace ArgumentError: command is too long

(This code blow requires you to include rbtrace in your gems)

To make a stack dump of your running rubyprocess, you could use somthing like this:

my_pid=1234
bundle exec rbtrace -p $my_pid -e 'Thread.new{GC.start;require "objspace";io=File.open("/tmp/ruby-heap.dump", "w"); ObjectSpace.dump_all(output: io); io.close}'

Unfortunately on FreeBSD / Mac OS X this results in (ArgumentError: command is too long)

A workaround for this, is to simply put the code in ruby file, and just load it. For example:
/tmp/rbcode.rb. With the following content

Thread.new{GC.start;require "objspace";io=File.open("/tmp/ruby-heap.dump", "w"); ObjectSpace.dump_all(output: io); io.close}

Next you can use rbtrace lik this:

bundle exec rbtrace -p $my_pid -e 'load("/tmp/rbcode.rb")'

Cron Job to clear Rails Cache

The rails file cache is something that keeps growing.
Here are some 'handy' snippets.

Delete all files older then 7 days. (replace -delete with -print to test it)

find ./tmp/cache/ -type f -mtime +7 -delete

Delete all empty folders. (mindepth prevents the deletion of the root folder)

find ./tmp/cache/ -type d -empty -delete -mindepth 1

The whenever.rb I use

job_type :command_in_path, "cd :path && :task :output"

every :day, at: "0:40" do
  command_in_path "find ./tmp/cache/ -type f -mtime +7 -delete"
end

every :day, at: "1:10" do
  command_in_path "find ./tmp/cache/ -type d -empty -delete -mindepth 1"
end