ianhuang / Apex-Batch-Job-Scheduler

Salesforce Apex batch job scheduler support execution sequencing and dependency
MIT License
15 stars 10 forks source link

In case of empty batch, order might be changed or job might be duplicated #3

Open olektymchenko opened 1 month ago

olektymchenko commented 1 month ago

Hello,

Thank you for providing such a valuable tool. I am currently encountering an issue where batches frequently return empty results in the start method, leading to an immediate transition to the finish method without processing. Each batch is executed within an independent group, and the execution time is only a few milliseconds. Additionally, the order of job execution often changes unexpectedly or job is executed twice.

Implementing a custom delay of 5 seconds has helped mitigate this issue. However, it would be greatly beneficial to have this functionality integrated into the package itself.

Thank you in advance for your assistance.

ianhuang commented 1 month ago

Hi Oleksandr,

Thanks for your email. It seems the empty results cause a problem. Would you mind providing your code changes so I can use it as a starting point?

Thanks and regards, Ian Huang

On Wed, Jul 31, 2024 at 9:52 PM Oleksandr Tymchenko < @.***> wrote:

Hello,

Thank you for providing such a valuable tool. I am currently encountering an issue where batches frequently return empty results in the start method, leading to an immediate transition to the finish method without processing. Each batch is executed within an independent group, and the execution time is only a few milliseconds. Additionally, the order of job execution often changes unexpectedly.

Implementing a custom delay of 5 seconds has helped mitigate this issue. However, it would be greatly beneficial to have this functionality integrated into the package itself.

Thank you in advance for your assistance.

— Reply to this email directly, view it on GitHub https://github.com/ianhuang/Apex-Batch-Job-Scheduler/issues/3, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABEKB7RCRCUEZYBCEN46KDZPDFW3AVCNFSM6AAAAABLYJ2FHSVHI2DSMVQWIX3LMV43ASLTON2WKOZSGQZTSOBVHA4TINY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

--

http://www.salesforce.com/ap/?d=70130000000sjmr&Elq_mid=email

Best regards, Ian Huang Senior Technical Architect | Salesforce http://salesforce.com/au M: +61 406 482816 | Email: @.*** Follow us on: [image: Twitter] http://twitter.com/salesforce [image: Facebook] https://www.facebook.com/salesforce [image: LinkedIn] http://www.linkedin.com/company/salesforce [image: YouTube] http://www.youtube.com/salesforce

https://smart.salesforce.com/sig/ihuang//us_mb/default/link.html

olektymchenko commented 1 month ago

Hello,

To reproduce this issue, please create one scheduled job with, for example, 10 batches, each in an individual group. Each batch should have 0 records in the start method, causing the finish method to execute instantly.

The current workaround I implemented at the beginning of the start method is as follows:

DateTime startTime = System.now();
while (System.now.getTime() - startTime.getTime() < 1000) {
    // waiting for 1 second
}

While this solution is not optimal, I noticed that in the BatchJobScheduler.cls class, batches are executed instantly via Database.executeBatch. A possible workaround might be to use System.scheduleBatch, specifying the minutesFromNow parameter with a value of 5 or 10 seconds.

Additionally, could you please add page layouts to the created objects? Currently, they are missing, and I do not have permission to create new ones. As a result, I need to change the view to "split view" every time to see a list of records, as the "table" view is not functional.