Wait to finish all batch job


i tested:

while(job.status().isCompleted()) {

but i have endless waiting . why ?
Fra dg


It can be for many reasons like work load on the cluster or the job itself is slow.
For the first case, you can increase the prioritize your job so that it will be executed right away and now have to wait for the queues to drain.

job.setPriority(9) // set a low value for higher priority

For the second case, you need to optimize your code:

  • think of reducing the number of fetch,
  • use limits and include to reduce the amount of data fetched
  • when you can, use stored calc fields to avoid run-time joins


Also keep in mind that job.status() is doing a network call. Used in while condition, you are going to flood the server. I would recommend setInterval to check periodically (every 2 seconds for instance).


Also please note that batch jobs have an allComplete function if you need to do something when all parts are done. See c3ShowType(JSBatchJobSpec).