views:

34

answers:

1

I have a model called Vote that gets changed very frequently (people voting on stuff). I do other analytics after a vote is save, such as interpolating if the voter is male/female, what age etc. This results in updating counters in (adult votes, women votes etc) the same model.

I wonder what's the best way to do this after save processing, should this be a background job (I use delayed_job plugin) or should this be best left as an after_save callback? Which is better also from performance standpoint?

I don't really need to show upto the second latest data to the user (even the after_save callback doesn't accomplish that anyway).

Thanks

+1  A: 

My rule of thumb is that if it takes longer than a second (on average) to complete - I shove it to a background job, otherwise I will keep in synchronous. I use delayed job, it works well and I have had no reason to leave it. I had one case where I didn't need to hit the database in the background job and I used a custom rake task, it was very efficient and saved me having to implement a background job processor.

Geoff Lanotte
Second this approach with a further point:If the task is non-critical to the usage of the application OR the user does not require this updated information immediately delayed_job it. e.g updating third party systems (invoicing perhaps) of a user name change does not impact on the users ability to use your application so use delayed_job
David Lyod