Pages

Wednesday, July 16, 2014

Force the batch server to execute batch jobs immediately and bypass the 60 second wait in one line of code! - [AX 2012]

In AX 2012, if you want to force the batch server to immediately check for awaiting batch jobs and execute them without waiting the 60 seconds for the server to discover them, you can call:

xApplication::checkForNewBatchJobs();

Why might you need this?

In my case, I need to call this because I think there is a bug caused by a race condition that can occur with reliable asynchronous (SysOperationExecutionMode::ReliableAsynchronous) processes that are called from the client.

What happens when you call a reliable asynchronous process client side, two things happen at the same time from `\Classes\SysOperationController\doBatch`:

  • Batch task record is inserted to \Data Dictionary\Tables\Batch)
  • Some sort of new thread is spun up asynchronously via `\Classes\SysOperationController\asyncWaitForBatchCompletion`

So, my theory on what can happen is the async polling process (`\Classes\SysOperationFrameworkService\waitForBatchJob`) will try and select the Batch record and may not find it because the Batch record hasn't finished inserting.

In my case, I've overloaded the doBatch() method and put some tracking logic with pessimisticLock that slows down the Batch insert just enough to periodically cause this...so I end up with batch jobs sometimes that are waiting ~60 seconds to be picked up.

2 comments:

  1. Good post Alex.
    I had trouble on a demo contoso box where the batch jobs didn't start. (I think data got screwed up in the background)
    Running the one line in a job saved me time.

    ReplyDelete
  2. Nice post,it's very informative.i found the best information.I updated my knowledge with this blog.it can help me to crack GIS jobs in Hyderabad.

    ReplyDelete