Multi Job with Quartz Scheduler not running

DevMarduk 1 Reputation point
2022-02-15T08:33:10.497+00:00

I've scheduled three job in my Service:

public partial class Service : ServiceBase
    {
        private IScheduler scheduler;
        private static log4net.ILog _logFile =
            log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public Service()
        {
            InitializeComponent();
        }

        protected override async void OnStart(string[] args)
        {
            _logFile.Info("Service OnStart");

            var factory = new StdSchedulerFactory();
            scheduler = await factory.GetScheduler();

            await scheduler.Start();
            var job = JobBuilder.Create<SearchJob>()
                .WithIdentity("SearchJob", "group1")
                .Build();

            var trigger = TriggerBuilder.Create()
                .WithIdentity("SearchJobtrigger", "group1")
                .StartNow()
                .WithCronSchedule(Settings.Default.SearchCronExp)
                .ForJob(job)
                .Build();

            var jobUpload = JobBuilder.Create<UploadJob>()
           .WithIdentity("UploadJob", "group1")
           .Build();

            var triggerUpload = TriggerBuilder.Create()
                .WithIdentity("TriggerUploadJob", "group1")
                .StartNow()
                .WithCronSchedule(Settings.Default.UploadCronExp)
                .ForJob(jobUpload)
                .Build();

            var jobAwaiter = JobBuilder.Create<AwaiterJob>()
                .WithIdentity("AwaiterJob", "group1")
                .Build();

            var triggerAwaiterJob = TriggerBuilder.Create()
                .WithIdentity("triggerAwaiterJob", "group1")
                .StartNow()
                .WithCronSchedule(Settings.Default.AwaiterCronExp)
                .ForJob(jobAwaiter)
                .Build();

            await scheduler.ScheduleJob(job, trigger);
            await scheduler.ScheduleJob(jobUpload, triggerUpload);
            await scheduler.ScheduleJob(jobAwaiter, triggerAwaiterJob);

            _logFile.Info("End Service OnStart");
        }

        protected override async void OnStop()
        {
            _logFile.Info("Service OnStop");
            await scheduler.Shutdown();
        }
    }

Consulting the log, I notice that the only the first job starts, the other two never start but there are no errors in the log. I tested the service in debug and the jobs are executed correctly, while installing the service compiled in Release no, the three services have a CronExp of 1,10,30 minutes respectively between one execution and the other

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,843 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Warren Joubert 91 Reputation points Microsoft Employee
    2022-02-15T19:56:36.117+00:00

    There wont be any effect of calling startNow() on a CronTrigger as it triggers the job based on cron expression supplied unlike time based SimpleTrigger.
    Your cron expression tells Quartz to run every x mins starting 0th minute of ever hour. Unless you start the scheduler at exactly 0th min, you will not see startNow effect.

    Hope this is clear to you. Refer Quartz tutorial-lesson-06 tutorials/documentation for more details.
    meaning your jobs will only run as per cronjob expressions.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.