Henrik Fransas
Feb 13, 2015
  4639
(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
Creating an Optimizely CMS Addon - Adding an Editor Interface Gadget

In   Part One   of this series, I covered getting started with creating your own AddOn for Optimizely CMS 12. This covered what I consider to be an...

Mark Stott | Aug 30, 2024

Configure your own Search & Navigation timeouts

The main blog Configure your own Search & Navigation timeouts was posted for years but you need copy the code to your application. We now bring tho...

Manh Nguyen | Aug 30, 2024

Joining the Optimizely MVP Program

Andy Blyth has been honoured as an Optimizely MVP, recognising his contributions to the Optimizely community. Learn how this achievement will enhan...

Andy Blyth | Aug 29, 2024 | Syndicated blog

Welcome 2024 Summer OMVPs

Hello, Optimizely community! We are thrilled to announce and welcome the newest members to the Optimizely Most Valuable Professionals (OMVP) progra...

Patrick Lam | Aug 29, 2024

Create custom folder type in Edit Mode

Content Folders, which are located in assets pane gadget or multichannel content gadget, allow you to add any type of block or folders. But...

Grzegorz Wiecheć | Aug 28, 2024 | Syndicated blog

Creating an Optimizely AddOn - Getting Started

When Optimizely CMS 12 was launched in the summer of 2021, I created my first AddOn for Optimizely CMS and talked about some of the lessons I learn...

Mark Stott | Aug 28, 2024