Try our conversational search powered by Generative AI!

Scheduled Job results in status FAILED when triggered by the scheduler

Vote:
 

Hi, 

I have a weird problem with a scheduled job: when triggered by the scheduler, the scheduled job results in status FAILED, message "Object reference not set to an instance of an object". Also, no message is logged in the log file. 

When the scheduled job is started manually, the scheduled job results in status OK; and it does write to the log file. 

 

I don't think the cause of the error is in the scheduled job code (I placed a breakpoint in the code, this only gets triggered when I start the scheduled job manually), but here is my code anyway: 

using EPiServer.Security;
using log4net;
using System.Reflection;

namespace Planet3.EpiServer.Templates.Admin.Test
{
    [EPiServer.PlugIn.ScheduledPlugIn(
    DisplayName = "Test Scheduled Job",
    Description = "Scheduled Job for Testing purposes",
    SortIndex = 1)]
    public static class TestScheduledPlugIn
    {
        private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        public static string Execute()
        {
            var resultMessage = string.Empty;
            Log.InfoFormat("Scheduled job Test is started.");

            if (PrincipalInfo.CurrentPrincipal.Identity.Name == string.Empty)
            {
                Log.InfoFormat("Anonymous Principal, so scheduled job is triggered by the scheduler");
                resultMessage += "Anonymous; ";
            }
            else
            {
                Log.InfoFormat("User Account = [{0}], so scheduled job is triggered manually",
                                    PrincipalInfo.CurrentPrincipal.Identity.Name);
                resultMessage += string.Format("Account=[{0}]; ", PrincipalInfo.CurrentPrincipal.Identity.Name);
            }

            if (System.Web.HttpContext.Current == null)
            {
                Log.InfoFormat("HttpContext.Current == null, so scheduled job is triggered by the scheduler");
                resultMessage += "HttpContext.Current == null; ";
            }
            else
            {
                Log.InfoFormat("HttpContext.Current exists, so scheduled job is triggered manually");
                resultMessage += "HttpContext.Current exists; ";
            }

            resultMessage += "The End.";
            return resultMessage;
        }
    }
}

    

BTW, the log file also contain the following logging: "DataAbstraction.ScheduledJob - 3.1.3  Scheduled job has already been executed 8de3f2b0-6e12-4716-a6f9-736f7e2f8944. " 

 

Hope you can help!

Best, Leonard

#71769
May 28, 2013 16:56
Vote:
 

Sounds like you may have a corrupt entry in your tblScheduledItems table. That error message might occur if the next execution date field in the database entry has passed. Run this query to find the rows:

select * from tblScheduledItem where pkID ='8de3f2b0-6e12-4716-a6f9-736f7e2f8944'

    

Blog posts for tips on debugging and logging from the scheduler:

http://www.epinova.no/blog/Tore-Gjerdrum/dates/2010/11/enable-debugging-in-episerver-scheduler/

http://world.episerver.com/Blogs/Tobias-Nilsson/Dates/2010/12/Troubleshooting-the-Scheduler/

#71777
Edited, May 28, 2013 20:04
Vote:
 

Thanks Arild, the second link was helpful for me: after deleting the rows from the scheduler tables, the scheduler runs good again. 

#74190
Aug 22, 2013 9:54
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.