Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Scheduled jobs not running when not logged in (CMS 10)

Vote:
 

I have 2 custom scheduled jobs that run on their schedules when I am logged in, however they stop running when I log out. How can I get them to run all the time, regardless of if I am logged in or not? The test site I am running the scheduled jobs on is password protected, and requires logging in to access it. Could this be the reason the scheduled job doesnt run when I log off? 

Any help would be much appreciated. This is my first time writing scheduled jobs.

The EmailerJob is scheduled to run every 15 minutes in the admin panel, and it does this successfully when logged in.

Code:

namespace mySite.Business.ScheduledTasks
{
    [ScheduledPlugIn
        (DisplayName = "Emailer Job")]
    public class EmailerJob : ScheduledJobBase
    {
        private readonly Injected _emailService;

        private bool _stopSignaled;

        private List _error = new List();
        private List _sentLog = new List();

        public EmailerJob()
        {
            IsStoppable = true;
        }

        public override void Stop()
        {
            _stopSignaled = true;
        }

        public override string Execute()
        {
          // the settings page has properties used in the job function (e.g. email addresses, content, retry attempts, delete file from server after [x] days, etc )
          var contentLoader = ServiceLocator.Current.GetInstance();
          var settings = contentLoader.GetChildren(ContentReference.RootPage).FirstOrDefault();          

          ...

            
          return string.Format(
                    "{0} Email(s) Sent
Details:
{1}
{2} Errors
Details:
{3}", _sentLog.Count, string.Join("", _sentLog), _error.Count, string.Join("", _error)); } } }
#182062
Sep 08, 2017 14:26
Vote:
 

A couple of things:
When the job runs automaticly you do not have access to httpcontext and that means that some of these ContentReference.... does not work, but I think the rootpage always works

The job runs under a special user that might not have the access to get children, you can run it with elaborated security if you need

#182063
Sep 08, 2017 14:52
Vote:
 

Hi Henrik. Thanks for your reply. I changed my approach in the end, creating a plugin to hold the settings after seeing this article https://www.epinova.no/en/blog/configuration-options-for-episerver-sites/ .

#182300
Sep 14, 2017 17:39
Vote:
 

For any other developers who run into similar issues, if you are using IIS, make sure to also check the Application Pool advanced settings for your site. I had to change the idle-timeout to 0 (default was 20 mins) and change StartMode to AlwaysRunning

#183066
Oct 04, 2017 10:55
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.