TaskScheduler provides a means to run rake tasks on a schedule triggered by a simple crontab entry. You build your rake tasks in the usual way and create a schedule for TaskScheduler to trigger them.
Include the TaskScheduler gem in your Rails application Gemfile:
gem 'task_scheduler', :git => 'git://github.com/mmell/task_scheduler.git'
rake task_scheduler:install:migrations rake db:migrate
In your Rails application, add a route
mount TaskScheduler::Engine => "/tasks"
then the url will be 0.0.0.0:3000/tasks/scheduled_tasks
config.action_mailer.default_url_options = { :host => "example.com" }
Visit the url where you have TaskScheduler::Engine mounted and create a Scheduled Task.
Create a shell script to trigger any waiting ScheduledTasks.
# /home/rails/cron_jobs/task_scheduler_cron.sh #!/bin/bash source /home/rails/.bash_profile # need to load rvm setup cd /home/apps/main_app/production /usr/bin/env rake RAILS_ENV=production task_scheduler:run
_Tip: It’s always a good idea to use full paths in scripts for cron._
1 * * * * /home/rails/cron_jobs/task_scheduler_cron.sh # run every hour
The controllers/task_scheduler/scheduled_tasks_controller expects there to be a layout named “admin”.
This project was originally available in the vendor/plugins of the Linksafe Ibroker on [Soureforge](linksafe.svn.sourceforge.net/viewvc/linksafe/rails/ibroker/trunk/vendor/plugins/at_linksafe_task_scheduler)
This project is released under the MIT-LICENSE.