Quartz.Net scheduler works locally but not on remote host

I have a timed quartz.net job working fine on my dev machine, but once deployed to a remote server it is not triggering. I believe the job is scheduled ok, because if I postback, it tells me the job already exists (I normally check for postback however). The email code definitely works, as the ‘button1_click’ event sends emails successfully.

I understand I have full or medium trust on the remove server. My host says they don’t apply restrictions that they know of which would affect it. Any other things I need to do to get it running?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Quartz;
using Quartz.Impl;
using Quartz.Core;
using Aspose.Network.Mail;
using Aspose.Network;
using Aspose.Network.Mime;
using System.Text;

namespace QuartzTestASP
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ISchedulerFactory schedFact = new StdSchedulerFactory();
                IScheduler sched = schedFact.GetScheduler();
                JobDetail jobDetail = new JobDetail("testJob2", null, typeof(testJob));
                //Trigger trigger = TriggerUtils.MakeMinutelyTrigger(1, 3);
                Trigger trigger = TriggerUtils.MakeSecondlyTrigger(10, 5);
                trigger.StartTimeUtc = DateTime.UtcNow;
                trigger.Name = "TriggertheTest";
                sched.Start();
                sched.ScheduleJob(jobDetail, trigger);
            }
        }
        protected void Button1_Click1(object sender, EventArgs e)
        {
             myutil.sendEmail();
        }
    }

    class testJob : IStatefulJob
    {
        public testJob() { }

        public void Execute(JobExecutionContext context)
        {
            myutil.sendEmail();
        }

    }

    public static class myutil
    {
        public static void sendEmail()
        {
            // tested code lives here and works fine when called from elsewhere
        }
    }
}

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The scheduler factory should be global to your application. In other words, declare it in Global.asax or similar that effectively gives you a global instance to operate with. You should start the scheduler in your application start if running ASP.NET.

Beware thought. ASP.NET recycles its processes which effective causes shutdown of scheduler (no jobs will run) until next next request comes in to web server to start the scheduler again. The recommended way is to have a windows service for running Quartz.NET jobs.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x