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
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?
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
Note to self: Turn off any jobs before deleting them from the project
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.
David, that is a god thing to do and probably something that will be forgotten :)
Great Ahsan, thanks!
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 ;)
https://github.com/valdisiljuconoks/TechFellow.ScheduledJobOverview/issues/6
The bug related to this issue is public. Here you can see about it.
http://world.episerver.com/support/Bug-list/bug/122061