JOb not firing with Quartz.Net as Windows Service and Asp.Net application

2,863 views
Skip to first unread message

Sebastien Matagne

unread,
Mar 26, 2015, 5:40:27 AM3/26/15
to quar...@googlegroups.com, s.ma...@philae.fr

Hi,

I have a trouble with my ASp.net application, I have tested several solutions but I don't see any issue on it. Thanks by advance for your advice.

I have installed and running Quartz.Net as a Windows Service. Quartz.Net is in the same folder as my API in order to execute jobs in it.

Below my global.asax Application_Start

public static ISchedulerFactory schedFact;
public static IScheduler scheduler;

protected void Application_Start()
{
    NameValueCollection properties = new NameValueCollection();
    properties["quartz.scheduler.instanceName"] = "ServerScheduler";
    properties["quartz.scheduler.proxy"] = "true";
    properties["quartz.threadPool.threadCount"] = "10";
    properties["quartz.scheduler.proxy.address"] = "tcp://localhost:555/QuartzScheduler";


    schedFact = new StdSchedulerFactory(properties);
    scheduler = schedFact.GetScheduler();
    scheduler.Start();

    MyAPI.Services.ScheduleTasks.JobScheduler.StartGenerateContract();
}

Here the class where my jobs are scrippted:

public class ScheduleTasks
{
    public static Dictionary<string, string> report;

    public class JobScheduler
    {
        public static void StartGenerateContract()
        {
            try
            {
                MailService.SendMail("StartGenerateContract", "Scheduletask",
                    new Exception(DateTime.Now.ToString()));


                IJobDetail job_generate = JobBuilder.Create<GenerateAndSendContract>()
                    .WithIdentity("generateContractJob", "group1")
                    .Build();

                ITrigger trigger = TriggerBuilder.Create()
                    .WithIdentity("trigger_contracts", "group1")
                    .ForJob("generateContractJob", "group1")
                    .StartNow()
                    .WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(01, 00))
                    .Build();

                MyAPI.MvcApplication.scheduler.ScheduleJob(job_generate, trigger);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
    }
}

Then my job that is in the same file and class ScheduleTasks

public class GenerateAndSendContract : IJob
{
    public void Execute(IJobExecutionContext context)
    {
        try
        {
            MailService.SendMail("GenerateAndSendContract", "Scheduletask");
                //my working code...
        }
        catch (Exception e)
        {
            MailService.SendErrorMail("GenerateAndSendContract", "ScheduleTasks", e);
        }
    }
}

My scheduleTask is perfectly executed because I receive the first email (StartGenerateContract), with the good interval. But the job is not executed cause the code in the class generateandsendcontract is not fired (no break point, no mail GenerateAndSendContract send).

Anything wrong in my code? Thank you for your help.

manuel gonzales

unread,
Mar 26, 2015, 10:37:23 AM3/26/15
to quar...@googlegroups.com, s.ma...@philae.fr
Its best practice to let the service run the job not the web app.  Use the web app to access quartz api to return jobs that are running.

Sebastien Matagne

unread,
Mar 26, 2015, 10:41:12 AM3/26/15
to quar...@googlegroups.com, s.ma...@philae.fr
Thank you for your answer. 
TO let the service run the job I have to configure it in the quartz_jobs.xml isn't it?

And then I delete the JobScheduler to let only the Ijob detail?

manuel gonzales

unread,
Mar 26, 2015, 11:33:31 AM3/26/15
to quar...@googlegroups.com, s.ma...@philae.fr
For the windows service
    Use the service that comes with the project

    Use the job-type to point to the actual job


For your web app use the scheduler to return the jobs - look at the constructor
Message has been deleted
Message has been deleted

Sebastien Matagne

unread,
Mar 26, 2015, 12:46:15 PM3/26/15
to quar...@googlegroups.com, s.ma...@philae.fr
Thank you it was very usefull !!! :)


Le jeudi 26 mars 2015 10:40:27 UTC+1, Sebastien Matagne a écrit :
Reply all
Reply to author
Forward
0 new messages