Quartz.NET - Doesn’t the job start?

I am trying to implement Quartz.NET as a Windows service in C #. My assignments do not work when I expect them to start working ... in general, in fact, as far as I can tell?

I have a schedule of my work, starting the next smooth minute after the "flight". However, when the next minute comes, I can’t say if something is really happening.

I would suggest that when my work starts, the CLI window will appear during the execution of the task, and the console operations will be visible (I even set it Console.ReadKey()there so that the window does not open and does not close so quickly I can’t see this), but as far as I can tell, the schedule simply does not complete the tasks.

I noticed that all the time in UTC and what StartTimeUtcwill be set to UTC, which is +6 hours from my local computer time, but I also assume that the Quartz scheduler handles this by calculating the runtime from my TimeZone setting, although I don’t know that I know to confirm this, or to confirm the ACTUAL time for which my schedule is set.

I suppose there is some way to configure the Common Logging assembly and use it to help me find out what my status is, but I still have to figure out what to do with this in order to enable some kind of log for feedback from my Windows Service, except for writing to the event log that I created for it.

My OnStart function of my windows service

protected override void OnStart(string[] args)
    {
        eventLog.WriteEntry("--- STARTING eLoyalty Scheduler Service ---");

        // construct a scheduler factory
        ISchedulerFactory schedFact = new StdSchedulerFactory();

        // get a scheduler
        IScheduler sched = schedFact.GetScheduler();

        // construct job info
        JobDetail jobDetail = new JobDetail("eLoyaltySchedulerService", null, typeof(PortalSchedulerJob));
        jobDetail.JobDataMap["jobSays"] = "eLoyalty Scheduler Service Executing!";
        jobDetail.JobDataMap["myStateData"] = new ArrayList(); 

        // fire every minute
        Trigger trigger = TriggerUtils.MakeMinutelyTrigger();

        // start on the next even minute
        trigger.StartTimeUtc = TriggerUtils.GetEvenMinuteDate(DateTime.UtcNow);

        // name it
        trigger.Name = "NextEvenMinute";

        // schedule it
        sched.ScheduleJob(jobDetail, trigger);

        // start the schedule
        sched.Start();

        eventLog.WriteEntry("--- STARTED eLoyalty Scheduler Service ---");
    }

The function My Job Execute () is as follows:

public void Execute(JobExecutionContext context)
    {
        try
        {
            string instName = context.JobDetail.Name;
            string instGroup = context.JobDetail.Group;
            JobDataMap dataMap = context.MergedJobDataMap;
            string jobSays = dataMap.GetString("jobSays");
            ArrayList state = (ArrayList)dataMap["myStateData"];
            state.Add(DateTime.UtcNow);

            Console.WriteLine("Instance {0} of PortalSchedulerJob says: {1} @ {2}", instName, jobSays, DateTime.UtcNow);
            Console.ReadKey();
        }
        catch (JobExecutionException Ex)
        {
            throw Ex;
        }
    }

, ACTUAL, ...?

+5
5

... , , Job, , .

, Console.WriteLine() Console.ReadKey() Windows-?

. - , , ...

0

Quartz.NET JobExecutionException: Quartz.net- 3:

Job.Execute(..) , IJob.Execute(..). , JobExecutionException. - , , "try-catch". , JobExecutionException, , , .

:

catch (JobExecutionException Ex)
{
   throw Ex;
}

- :

catch (Exception err)
{
    // Only allow JobExecutionException exceptions to be thrown...
    throw new Quartz.JobExecutionException(err);
}

:

_globalJobListener = new GlobalJobListener();
sched.AddGlobalJobListener(_globalJobListener);


public class GlobalJobListener : Quartz.IJobListener
{
    public GlobalJobListener()
    {
    }

    public virtual string Name
    {
        get { return "MainJobListener"; }
    }

    public virtual void JobToBeExecuted(JobExecutionContext context)
    {       
    }

    public virtual void JobWasExecuted(JobExecutionContext inContext, JobExecutionException inException)
    {
        if (inException != null)
        {
            // Log/handle error here
        }
    }


    public virtual void JobExecutionVetoed(JobExecutionContext inContext)
    {

    }
}
+8

Windows :

static class Program
{
    static void Main()
    {
        var servicesToRun = new ServiceBase[] 
            { 
                new CassetteDeckService() 
            };

        if (Environment.UserInteractive)
        {
            var type = typeof(ServiceBase);
            const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
            var method = type.GetMethod("OnStart", flags);

            foreach (var service in servicesToRun)
            {
                method.Invoke(service, new object[] { null });
            }

            Console.WriteLine("Service Started!");
            Console.ReadLine();

            method = type.GetMethod("OnStop", flags);

            foreach (var service in servicesToRun)
            {
                method.Invoke(service, null);
            }
            Environment.Exit(0);
        }
        else
        {
            ServiceBase.Run(servicesToRun);
        }
    }
}

Windows ( Windows, ).

+2

. -, , , , .

NLog Common.Logging, Quartz ( , Simple Logging Facade, ). app config, , :

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <section name="slf" type="Slf.Config.SlfConfigurationSection, slf"/>
        <sectionGroup name="common">
            <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
        </sectionGroup>
    </configSections>


    <quartz>
        <add key="quartz.threadPool.threadCount" value="20" />
        <add key="quartz.jobStore.misfireThreshold" value="420000" /><!-- 7 minutes -->
    </quartz>


    <slf>
        <factories>
            <factory name="nlog" type="SLF.NLogFacade.NLogLoggerFactory, SLF.NLogFacade"/>
        </factories>

        <loggers>
            <logger factory="nlog"/>
        </loggers>
    </slf>

    <common>
        <logging>
            <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog">
                <arg key="configType" value="FILE" />
                <arg key="configFile" value="~/NLog.config" />
            </factoryAdapter>
        </logging>
    </common>

</configuration>
0

if you want to debug your work, keep the visual studio open, in your assignment:

System.Diagnostics.Debugger.Launch ();

which will allow you to connect to the debugger in the visual studio, and you can see what happens.

Alternatively, if you want the general log to work, send me a message as I have all been working fine in my Windows service.

0
source

All Articles