Scheduled Tasks Timing BUG

Matthew Butler asked on September 21, 2022 16:34

I have a scheduled task with a start time set to 2022-07-25 5:57 and set to run every 7 days, and if I manually run now "Last run" gets set 2022-09-21 15:30, but "next run" gets set to 2022-08-01 5:57.

This means when I run the task again, it runs but then fails to complete the task once it returns. So is left running. The error given is "BaseTime has to precede currentTime!"

This then means the task is blocked and I have to reset in DB

Recent Answers


Brenden Kehren answered on September 21, 2022 22:05

My suggestion would be if its a custom scheduled task, to delete it and set the start date/time for some time in the future. Then be sure to set it to run on the schedule you're looking for. If your frequency is once per week, then

  • set the Period field to Day
  • set the Start time field to a time in the future on the actual day and hour/minute you first want it to execute
  • set the Every field to 1
  • check all the boxes you for the Days you want the task to execute on.

If you want to specifically execute it every Sunday morning at 2am, then your settings would look like this:

Image Text

This should help resolve the issue you're having.

0 votesVote for this answer Mark as a Correct answer

Matthew Butler answered on September 22, 2022 16:21

I think the issue is manually executing a task that is currently disabled sets the last run to now, but doesn't update the "Next run", which then means next time it runs it breaks.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on September 22, 2022 16:46

Manually running it does not modify the next run if it's disabled or enabled.

0 votesVote for this answer Mark as a Correct answer

Matthew Butler answered on September 22, 2022 18:42

Yes and this means next time you manually run it then errors and doesn't complete

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on September 22, 2022 18:46

If this is a custom scheduled task, I'd suggest adding some error handling in your code to it gracefully exits the code and shows it's completed even if it does error out. This is probably the issue you're experiencing if it's a custom task.

0 votesVote for this answer Mark as a Correct answer

Matthew Butler answered on September 22, 2022 19:35

My task does have error handling, but it is completing successfully, it’s failing once it returns from the execute.

Thanks

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on September 22, 2022 19:40

Without seeing code, it's hard to tell. My guess is it isn't a bug in Kentico but a big in your code somewhere. We've written a hundred or more custom scheduled tasks and not experienced the issue your talking of unless our custom code errors out and doesn't finish properly.

Maybe debug through your task and see what happens through your code.

0 votesVote for this answer Mark as a Correct answer

Matthew Butler answered on September 22, 2022 22:17

I’ve removed all the code so just an empty task, and I’m seeing the same issue.

So create a custom task, set schedule but don’t enable. Manually run twice, on 2nd run the task errors with the above error, and the last result isn’t set and task remains running

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.