You need to sign in to do that
Don't have an account?
boBNunny
Workaround for Sleep/Pause/Wait?
We have a webservice that sometimes gets inundated with requests from an APEX trigger we have. So, we wrote a .NET batch program to do the requests via API through SFDC with a 45 second delay between requests. We'd like to make that a Batch APEX, however, I can't find any way to make the APEX code pause between submittals. I tried a loop checking on the time, but that causes 200K worth of script statements which exceeds governor limits too.
Does anyone have any ideas?
Thanx!
I'd be very surprised if SalesForce implemented a wait or sleep method as this would hold up transactions and wouldn't be very fair on a multi-tenanted SaaS platform.
When you say the .NET batch program fires through SFDC, what do you mean? Is the inundated webservice a SFDC webservice or another host and you are using SFDC as a proxy?
It doesn't need to be transactional to where it's holding up a transaction. They can limit it to Batch APEX. Then it can be checked to make sure it's not in the middle of a transaction. But we really need it because calling web services in batches can overwhelm them and that makes the application the weakest link and not truly scalable.
BTW, when I say .NET through SFDC, I mean that we resubmit some items for a custom Lead Assignment by setting the flag for it to call the Lead Assignment web service. That service gets flooded and can't handle hundreds of requests in a 1 minute span.
I am stucked up in similar kind of problem. Did you succedded in resolving this ? Please share with me. I want to have some
knid of wait statement between the two submittals Apex batch.
Please help, its urgent
Thanks,
Pragati
Thanks,
Swagat
Long startingTime = System.now().getTime(); // Num milliseconds since Jan 1 1970
Integer delayInMilliseconds = 1000; // One-second delay
while (System.now().getTime() - startingTime < delayInMilliseconds) {
// Do nothing until desired delay has passed
}
public static void sleep(Integer sleepSeconds) {
Long startTS = System.currentTimeMillis();
HttpRequest req = new HttpRequest();
req.setEndpoint('http://1.cuzillion.com/bin/resource.cgi?sleep=' + sleepSeconds);
req.setMethod('GET');
Http http = new Http();
HTTPResponse res = http.send(req);
Long duration = System.currentTimeMillis() - startTS;
System.debug('Duration: ' + duration + 'ms');
}
Via - http://stackoverflow.com/a/16817451/1084806
count = [SELECT id FROM TASK LIMIT 50000 ALL ROWS ];
count.clear();
Obviously, this wastes SOQL queries and you'll need to change the limit parameter depending on whatever else you have in memory. But in busy times of the day, that select may take a second or more each time it's executed.
OF COURSE this is a wasteful practice. SFDC has stated pretty clearly they'll never implement a sleep function, and if you use this technique sparingly it's not that sinful.
How Can I achieve this in Salesforce:
try {
Thread.sleep(1 * 1000); // Wait for a second
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}