apex scheduler- what if scenarios?

烈酒焚心 提交于 2019-12-12 05:29:55

问题


I'm looking into using apex scheduler to run a batch job. We can run it whenever we want, say 3 am when traffic is low, but I'm trying to anticipate some 'Oh-Crap' Scenarios. Can you guys help answer these questions for me?

Setup:

When the user modifies a territory 100k's of records can get updated.

Questions:

  1. What are some scenarios that can realistically cause my jobs to not terminate? I thought of a scenario of- when a user is editing a contact which happens to be in one of the batches is being run.

  2. What are some good practices for dealing with jobs that don't terminate? I was thinking about scheduling another batch job 2 hours after this one, but I don't see my boss liking that. I thought about maybe doing something in the finish() method- but don't know what exactly.


回答1:


  1. Any error in a batch will stop that batch from finishing correctly.
  2. I suggest you do some kind of check to know that you processed everything. What I usually use for batches is to mark somehow the records that need processing to distinguish them from the ones that don't. When I finish processing a batch, I mark the records as processed. Then you can check in the finish() method if any record still needs processing and reschedule the batch to run again.


来源:https://stackoverflow.com/questions/11067581/apex-scheduler-what-if-scenarios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!