Try our conversational search powered by Generative AI!

Henrik Fransas
Feb 13, 2015
  4529
(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

Comments

henriknystrom
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
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
valdis Feb 16, 2015 10:07 PM

https://github.com/valdisiljuconoks/TechFellow.ScheduledJobOverview/issues/6

Feb 19, 2015 08:43 AM

The bug related to this issue is public. Here you can see about it.
http://world.episerver.com/support/Bug-list/bug/122061

Please login to comment.
Latest blogs
Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog