Custom task run on its own

Sean Dooley asked on May 23, 2022 15:34

We have recently had an issue where a custom task ran unexpectedly, as it is only called by another scheduled task which had finished over 3 hours before.

Below is a quick overview of our custom scheduled tasks around the date/time in question. The overview includes what time a task started and finished, descriptions and any notes for reference.

5/7/2022 8:32:05 AM DisableInactiveProducts COMPLETED
    Document checkout by public user instead of administrator
5/7/2022 6:45:02 AM ProductCleanupTask ProductCleanupComplete
    Unassigned Product Pages: removed [0/0] and 0 errors.
    Unassigned Product SKUs: removed [0/0] and 0 errors.
5/7/2022 6:45:02 AM ProductCleanupTask INITIALIZING
5/7/2022 6:30:20 AM DisableInactiveProducts BEGIN
5/7/2022 3:10:02 AM ProductCleanupTask COMPLETED
    Unassigned Product Pages: removed [0/0] and 0 errors.
    Unassigned Product SKUs: removed [0/0] and 0 errors.
5/7/2022 3:10:02 AM ProductCleanupTask INITIALIZING
5/7/2022 3:10:02 AM ProductImportTask COMPLETED
    Product import completed with errors. Added 1 product(s). Updated 472 product(s). Skipped 10115 product(s).
5/7/2022 3:10:02 AM ProductMenuTask COMPLETED
5/7/2022 3:04:22 AM ProductMenuTask INITIALIZING
5/7/2022 3:04:21 AM DisableInactiveProducts COMPLETED
5/7/2022 3:04:17 AM DisableInactiveProducts BEGIN
5/7/2022 1:30:03 AM ProductImportTask INITIALIZING

The ProductImportTask calls the following tasks while it is running.

  • DisableInactiveProducts
  • ProductMenuTask
  • ProductCleanupTask

For some reason a DisableInactiveProducts task unexpectedly started at 6:30:20 AM. There are no tasks setup to run DisableInactiveProducts manually. There is also a ProductCleanupTask which started at 6:45:02 AM, however that task is scheduled to run everyday at that time.

The DisableInactiveProducts task accepts a list of product SKUs from the a external API, then disables any products which are not in the external API response. If there are no product SKUs provided, the task would not run. We are assuming the external API returned a response, yet may not have returned the expected results resulting in a large number of products being disabled.

A few questions remain

Why did a DisableInactiveProducts task, which is only called in code at the end of a ProductImportTask, start at 6:30:20 AM?

When the DisableInactiveProducts task ran at 6:30:20 AM, what was returned in the product feed?

When the DisableInactiveProducts task ran at 6:30:20 AM, why was the user for document changes showing as public instead of administrator?

Recent Answers


Brenden Kehren answered on May 23, 2022 16:41

I probably won't have specific answers, but I can tell you the scheduling engine sometimes has a mind of its own, especially when it comes to running tasks in a daisy chain like that. I'd highly recommend the following:

  • if you're executing the scheduled task manually, does it have a "next run" date?
  • if you're executing the scheduled task manually or in code, are you calling the right methods to do so?
  • it doesn't look like you're logging a completion event for the DisableInactiveProducts task. Was it possibly still running when you tried to manually execute it? Kentico won't create 2 running instances at one time, they will be queued in order of the request.

There could be some other issues as well but I'd start there.

0 votesVote for this answer Mark as a Correct answer

Sean Dooley answered on May 23, 2022 17:09 (last edited on May 24, 2022 14:56)

if you're executing the scheduled task manually, does it have a "next run" date?

We have not setup the ability to run the DisableInactiveProducts task manually, it is only run via ProductImportTask which according to the log entries finished over 3 hours earlier.

if you're executing the scheduled task manually or in code, are you calling the right methods to do so?

Yes, we think so. The logic which is in place has been running without issue for over 6 months.

it doesn't look like you're logging a completion event for the DisableInactiveProducts task. Was it possibly still running when you tried to manually execute it? Kentico won't create 2 running instances at one time, they will be queued in order of the request.

From the log entries we have seen so far, we can see where DisableInactiveProducts tasks begin and end. As DisableInactiveProducts cannot be called manually, we are unsure how the custom task has started.

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on May 24, 2022 15:11

Hi Sean,

How exactly your DisableInactiveProducts task configured? Is it disabled, or enabled and set up to run "Once" with the datetime in the past?

I've noticed sometimes if the task is enabled, set to run "Once" and date time in the past, if you open edit dialog for this task and just click "Save" without updating anything - it will run the task for some reason.

0 votesVote for this answer Mark as a Correct answer

Sean Dooley answered on May 24, 2022 15:58

Quick update ...

A scheduled task for DisableInactiveProducts which was previously redundant, had been updated to run daily at 6:30:00 AM which probably answers two of our questions.

The remaining question about what was in the product feed API response is still unknown and is a question outside of this forum.

0 votesVote for this answer Mark as a Correct answer

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