Running Jobs More Frequently (Than Hourly) on Heroku
Heroku allows you to run cron jobs at most every hour. However, there are many tasks that need to be run more frequently than that. Solution? delayed_job; here’s how…
# Called by Heroku once per day (for free!)
task :cron => :environment do
# Runs this task every five minutes (24*60/5=288) using delayed_job
1.upto(288) do |run|
SomeModel.delay(:run_at => (run * 5).minutes.from_now).some_method
end
end
nil is not a symbol
Thanks for that reminder, delayed_job! Almost as helpful as “Windows error 32.”
The real issue here is that the handler field in your delayed_jobs table is not large enough to hold the serialized version of your delayed method call. The “text” data type has a maximum storage capacity of 65535 bytes (in MySQL) which might be too small for some calls. For example, if you are using an object that contains one or more text field attributes.
The solution is to change your handler field from text to longtext (yes, that’s right - longtext). So, for MySQL users just…
alter table delayed_jobs change column handler handler longtext null default null;