Try our conversational search powered by Generative AI!

Henrik Fransas
Feb 13, 2015
(0 votes)

Important information about a bug in scheduled tasks

Update: It seems like the code in the old task is not executed, what happens is that EPiServer will keep it in the database and try to execute it as it was scheduled but will fail every time because it can not find the code/class. This is nothing that is dangerous but if the task is scheduled to run often, it might be a thing that will fill up the logs with errors and so.

I have reported this as a bug to support but I think it is good to inform it here as well.

We have noticed that when we delete a scheduled task that is created by code it does go away from the admin and the site, but it is still running and still exists in the database.

This is not god because it can do that things are happening in the background that you are not aware of.

To recreate it do like this (I did it in a Alloy site just to verify that it was not only our code that did this):
Create a new scheduled task, for example I did one just for test that looks like this that does not do anything that would crash anything else:

using System.Globalization; using DeployToAzureDemo.Models.Pages; using EPiServer; using EPiServer.Core; using EPiServer.DataAbstraction; using EPiServer.Filters; using EPiServer.PlugIn; using EPiServer.ServiceLocation; using EPiServer.Web; namespace DeployToAzureDemo.Business { [ScheduledPlugIn(DisplayName = "[Testjob] Count All Pages", Description = "Get all pages below startpage and count them")] public class CountAllPages { public static string Execute() { var iContentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>(); var pagePageTypeId = iContentTypeRepository.Load<NewsPage>(); var propertyCriteriaCollection = new PropertyCriteriaCollection { new PropertyCriteria { Condition = CompareCondition.Equal, Name = "PageTypeID", Type = PropertyDataType.PageType, Value = pagePageTypeId.ID.ToString(CultureInfo.InvariantCulture), Required = true } }; var pagesOfCorrectType = DataFactory.Instance.FindPagesWithCriteria(new PageReference(SiteDefinition.Current.StartPage.ID),propertyCriteriaCollection); return string.Format("There are {0} number of pages with the pagetype: {1} below startpage", pagesOfCorrectType.Count, pagePageTypeId.Name); } } }

Compile and go into Admin and schedule it to run once every minute
Let it run for a while and while that go into the database and run these queries:

Declare @ID varchar(50) Select @ID = pkId From [dbo].[tblScheduledItem] Where [Name] = '[Testjob] Count All Pages' Select * From [dbo].[tblScheduledItem] Where pkID = @ID Select top 20 * From [dbo].[tblScheduledItemLog] Where fkScheduledItemId = @ID Order by 1 desc

Now you will see that it is running good.

After that update your code by delete the class/job you just created, you can delete the file completely.
Recompile and go into admin and see that the job is gone.
After that execute the script above again against the database and you will see that the task is still there and it is still running every minute...

To fix this you have to manually delete the task from the database and to do that all you have to do is run this SQL script. (In you environment you have to change the name to the one of the job you want to delete)

Declare @ID varchar(50) Select @ID = pkId From [dbo].[tblScheduledItem] Where [Name] = '[Testjob] Count All Pages' Delete from [tblScheduledItemLog] Where fkScheduledItemId = @ID Delete from [tblScheduledItem] Where pkID = @ID
Feb 13, 2015


henriknystrom Feb 13, 2015 09:45 AM

When you are referring to "things are happening in the background" what would that be? From what I can recall, the scheduler will continue to try to run the job even after deletion, but when it cannot find any matching job code, it simply does not do anything. It is of course not optimal if it keeps trying all the time, but I'm just wondering if you have found anything else?

Henrik Fransas
Henrik Fransas Feb 13, 2015 09:53 AM

Thanks Henrik

Ok, then it is not so dangerous that I thought, the error I get is:

3.1.2 Failed to execute job 1a481a59-465f-40c5-b984-17471e69c9f0

System.NullReferenceException: Object reference not set to an instance of an object.

at EPiServer.DataAbstraction.ScheduledJob.InternalExec(Boolean startThread)

System.NullReferenceException: Object reference not set to an instance of an object.

at EPiServer.DataAbstraction.ScheduledJob.InternalExec(Boolean startThread)

Since the error reference to the code in EPiServer it was hard to understand what exactly was happening.

The big problem for me now is that we had a couple of jobs that ran every minutes and that are filling up our logs with errors

David Sandeberg
David Sandeberg Feb 13, 2015 11:29 AM

Note to self: Turn off any jobs before deleting them from the project

Feb 13, 2015 11:35 AM

Yes that seems strange, as the entries are being added to DB even thought the job is deleted. Have added a bug, will come up with some info. later.

Henrik Fransas
Henrik Fransas Feb 13, 2015 11:35 AM

David, that is a god thing to do and probably something that will be forgotten :)

Henrik Fransas
Henrik Fransas Feb 13, 2015 11:36 AM

Great Ahsan, thanks!

valdis Feb 16, 2015 10:03 PM

For me it sounds like excellent "exclamation mark" icon code behind in "Scheduled Jobs Overview" library :) Thanks for the code and I really should now push latest version out ;)

valdis Feb 16, 2015 10:07 PM

Feb 19, 2015 08:43 AM

The bug related to this issue is public. Here you can see about it.

Please login to comment.
Latest blogs
Change the IP HTTP Header used for geo-lookup in Application Insights


Johan Kronberg | Jun 10, 2024 | Syndicated blog

Copying property values

In this article I’d like to show simple Edit Mode extension for copying property values to other language versions. In one of my previous blogposts...

Grzegorz Wiecheć | Jun 8, 2024 | Syndicated blog

Auto-translate with OpenAI GPT-4o in Optimizely CMS

Improvements for Episerver.Labs.LanguageManager! It's now possible to auto-translate both a page and its children at the same time! Additionally, m...

Tomas Hensrud Gulla | Jun 7, 2024 | Syndicated blog

Upgrade To Optimizely CMS 12 Issue: List item fields have become Required

There are many funny details to be aware of when upgrading from Episerver CMS 11 to Optimizely CMS 12. One of them that might feel a bit confusing ...

Allan Thraen | Jun 7, 2024 | Syndicated blog