Batch job - Distributing workload by from from code dynamically create multiple batch jobs
Our scenario is that we have a customized function the create project invoices for all projects that projects with chargeable transactions.
Initially all this work was handled by a single batch task in batch job. The customer has many many projects so the batch job could take a whole day to complete.
- We made an attempt to let a "main"-task in batch find and loop over all projects with chargeable transactions.
- From this one batch task per each ProjectId is created.
- The above works fine...
- ...but after a successfull batch-run all the ProjectID-tasks are kept in the batchjob.
- So when the same batchjob is started up again (due to recurring schedule) all the tasks from the previous run are still remaining in the batchjob.
- The goal would be to that at each new run the batchjobn should only consist of the "main"-task that locates all ProjectId:s and create a new fresh set of batch tasks
So our problem is how to get e "clean sheet" at each startup of a new batch run.
Is there any "best practice"-way to achieve what i describe above?