Handling Frequent Tasks

Standard

Once I had to make an application (bpoloan) that will provide some money in the user’s account upon their request and then try to get it back later from their account. How many times a day it will try to debit, i.e., try to get the money back was configurable. So I came up with the following solution for picking up eligible users:
String nextCycle;
if(debitFrequency <= 24){
nextCycle = (24/debitFrequency) + “/24”;
}
else{
nextCycle = ((24*60)/debitFrequency) + “/1440”;
}
String query = “update ” + tableSubscriberInfo + ” set processor_id = ‘” + threadName + “‘, event_id = ” + eventID + ” where active = 1 and modification_date < sysdate-” + nextCycle;

Here, if debitFrequency is 1 then nextCycle is “24/24”, so the condition check will be modification_date<sysdate-24/24 => modification_date<sysdate-1, so a user’s account will be debited after 24 hours of credit.

If debitFrequenct is 3 then nextCycle becomes “8/24”, so the condition check will be modification_date<sysdate-8/24 , so the application will try to debit after 8 hours of credit and will recurr after every 8 hours.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s