views:

33

answers:

1

Hi,

I'm not sure how to do this...

I have a database which contains a messages and categories tables.

The categories table has a field which has a count of the number of messages related to it.

Sometimes however I need to deactivate (active = 0) a message, at the moment this doesn't then update the category table... I will implement this is in the end but for the time I would just like to run a script perhaps daily that goes through all the categories, counts up the messages and updates the field.

What the best way of doing this?

Thanks in advance

Chris

A: 

If you are happy to do this manually you can create a Rake task. Push to Heroku, then execute using "heroku rake".

You could also use delayed_job, which Heroku supports. This does however cost you money $0.05 an hour. Given that it won't run very often or for very long, might be quite cheap.

The only other way I have done this stuff is to make a controller that wraps the logic and then call this. You can use one of the many and various ping services to trigger the call (these services are generally setup to request a page in your site) or setup a cron to use wget or curl to make the request.

Toby Hede
AND ... all of that said, it's probably 1 line of code to add this to your Rails app. Rails has built-in support for cached counting, or you can just setup a callback in your model.
Toby Hede
+1 to my comment, not my answer.
Toby Hede