Oh My Cron
Oh boy. I feel like I may never truly understand how cron works compared to other task scheduling applications. Today I went through a whole mess of steps to try and get a job scheduled to automatically generate my github contributions chart.
What happened?
So, I was able to use the lovely githubchart gem to generate my githubchart SVG with no issues at all. It was so simple.
> gem install githubchart
> githubchart -u onlymattjohnson ./github.svg
Since this was so easy I thought just dropping that in cron
to run every 15 minutes or so would be straightforward. I get to keep hugo generating my static site and then in the background this script can just refresh the image.
⛔ I was wrong.
I added the commands I needed to the an entry in crontab -e
and then waited to see the image render. It did not. I checked my logs and I see this message (I removed some of the folder names because you don’t need to know all that)
/usr/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': can't find gem githubchart (>= 0.a) with executable githubchart (Gem::GemNotFoundException)
from /usr/lib/ruby/2.7.0/rubygems.rb:294:in `activate_bin_path'
from /home/XXXXXXXXX/gems/bin/githubchart:23:in `<main>'
Can this be fixed?
Every suggestion google through back at me involved installing RVM, which to be fair I should have already done. From there, I should let RVM setup my cron headers.
> rvm cron setup
So, I installed RVM, which was fast. Then, I installed ruby through RVM, which did not go so fast. Finally, I reinstalled githubchart
with the new ruby being managed by RVM.
Now, I entered the magic command rvm cron setup
, verified that my crontab now had the appropriate headers. I crossed my fingers 🤞 and… IT WORKED 🎉
So, I guess if you want to use ruby gems and cron, make sure to use RVM.