Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax runs jobs multiple times before completing #17

Open
jeremyhiggs opened this issue Dec 16, 2016 · 1 comment
Open

Relax runs jobs multiple times before completing #17

jeremyhiggs opened this issue Dec 16, 2016 · 1 comment

Comments

@jeremyhiggs
Copy link

I have a few classes that extend relax.BatchableProcessStep and are created through JobScheduler.CreateOneTimeJob() with a start time of Datetime.now().addMinutes(-5).

After a few minutes, the job kicks off, and I can see through the dev console that it's running.

However, I find that one minute after the batch has started, the same batch class has been spawned again with the exact same parameters. Sometimes it's 1 extra copy, other times it's 2 extras.

There's no error taking place in the batch classes (I've surrounded them with try/catch), and the complete() method is being used at all exit points.

Attaching two files:

  • Listing of Apex Jobs, see "UpdateItemStatusBatch": screen shot 2016-12-16 at 16 07 38
  • Output from the jobs that has been sent into Slack. Exactly the same output from the batch running twice. screen shot 2016-12-16 at 22 11 15

I looked through the code, and wonder if this is what's happening:

  1. Job kicks off and spawns the batch
  2. In the meantime, the job scheduler runs again and sees that the job is still "Queued" (I've never seen it have a status other than "Queued" or "Completed"), that the next run time is before now and runs it again.
  3. By the time the job scheduler runs again, both instances have been completed.

So...

  1. Is there a reason why the job status never gets updated?
  2. Alternatively, if Decrease the job scheduler execution time from 5 mins to 30 seconds #1 is working as expected, can JobScheduler.GetNextRunTimeForJob() check if it's a one-time job and has already been created? In which case, it doesn't return a run time.

FWIW, I tried setting up the code on my own sandbox, but ran into a ton of errors while deploying it. Else I would have tried to fix it myself.

@jeremyhiggs
Copy link
Author

It also doesn't make a difference if the job is to be deleted after it is run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant