-1

I am very new to quartz scheduler and it's a little more all-encompassing than I need it to be.

All I want to is to run a task on the 35 with minute of every hour regardless of when the application has been started.

Apparently this can be done with cron jobs. Code I have so far is

StdSchedulerFactory factory = new StdSchedulerFactory();
        IScheduler scheduler = await factory.GetScheduler();
        await scheduler.Start();

        IJobDetail hourlyJob = JobBuilder.Create<Hourly>()
        .WithIdentity("hourlyJob", "Jobs")
        .Build();

        ITrigger hourlyJobTrigger = TriggerBuilder.Create()
            .WithIdentity("hourlyJobTrigger", "Jobs")
            .StartNow()
            .WithCronSchedule("59 0 0 ? * * *")
            .Build();


        await scheduler.ScheduleJob(hourlyJob, hourlyJobTrigger);

To my understanding this is supposed to make the task run on every 59th second (for the purpose of testing) of the minute. Doesn't seem to be trigerring though.

americanslon
  • 4,048
  • 4
  • 32
  • 57

1 Answers1

1

You can do it with next cron expression

0 35 0/1 ? * * *

This cron expression means that it will trigger every hour in 35 minutes every day.

Our code will be

ITrigger hourlyJobTrigger = TriggerBuilder.Create()
            .WithIdentity("hourlyJobTrigger", "Jobs")
            .StartNow()
            .WithCronSchedule("0 35 0/1 ? * * *")
            .Build();
Alexcei Shmakov
  • 2,203
  • 3
  • 19
  • 34
  • Obviously I can't wait for an hour every time i want to test this thing so I modified my code to run the job every 59th second of the minute for ease of testing, or at least that's what I think the cron expression in my initial post means. Do you have any idea why it's not triggering? – americanslon Jun 01 '18 at 19:52
  • Your cron expression in the question will trigger only at 00:00:59am every day. You should change it to _59 0/1 0 ? * * *_ – Alexcei Shmakov Jun 01 '18 at 19:57