Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run daily tasks/scripts in a Rails project?

I'm working on the billing system for my app, but I'm not sure how to go about setting up scripts that run daily, one to send out payment reminders (email), and another to downgrade subscriptions that have not been renewed.

  • Any tips on how to do this?
  • Any gotchas I need to watch out for?
  • Any gems that I might be able to use?

I've completed most of the purchasing side already, so am not looking for gems like paypal_recurring, or stripe - just need to handle the payment reminders and dealing of accounts that have expired.

like image 615
A4J Avatar asked May 06 '12 23:05

A4J


2 Answers

I've done this a number of ways and there are a bunch of ways to do it. I think the current best practice is to use Resque to queue the jobs and Rescue Scheduler to schedule them.

Resque is a solid 'job scheduling' app that can handle all kinds of tasks for you. Resque Scheduler can be fed full cron expressions (in addition to other methods of scheduling tasks) to manage the jobs.

One of the advantages of this approach is that you get the Resque Web app that gives you a web app to use for monitoring the jobs (or launching them for one-off job runs).

I've used this approach with Heroku and it works well and has been reliable.

like image 184
Kevin Bedell Avatar answered Sep 28 '22 01:09

Kevin Bedell


Whenever at https://github.com/javan/whenever is a nice way to define scheduled tasks using cron. Or you can use cron directly: http://www.ameravant.com/posts/recurring-tasks-in-ruby-on-rails-using-runner-and-cron-jobs

like image 22
synecdoche Avatar answered Sep 28 '22 01:09

synecdoche