Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a table which has the amount,entrydate and amtperday field , which is to decrease daily.

so what is better running the cron job daily to decrease amount.

or

or at the time of fetching data calculate the amount perday with the date field , i can get the no. of day

amount = amount- no.of day * amtperday

so which is good Please suggest ?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

First solution (cron):

(+) Database is in consistent state, different clients don't have to know about logic

(+) Performance friendly

(-) Have to have compensation strategy in place in case your cron runs more often or less often than it has to for whatever reason

Second solution:

(+) If the formula for calculation changes often than it doesn't impact the data - can adjust the formula

(-) Performance not friendly (cannot use indexes on calculated fields)

(-) Prone to "copy & paste" of the formula between different clients

Without knowing too much about your situation, I would go with running a daily cron.

share|improve this answer
    
If you want to go with cron and get rid of the "compensation strategy" you can use manageable schedulers (Quartz, Quartz.Net) and gain control over periodic execution (suspend/reactivate, change execution period etc). –  Jacek Prucia Mar 24 '11 at 9:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.