Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cron Scheduler every day at 12 midnight

I implement a schedule in MVC app to run job in every day midnight. This is the code.

    IScheduler sched = container.Resolve<IScheduler>();
    sched.JobFactory = new AutofacJobFactory(container);
    sched.Start();

    IJobDetail job = JobBuilder.Create<ProcessInvoiceJob>()
           .WithIdentity("job1", "group1")
           .Build();

    ITrigger trigger = TriggerBuilder.Create()
        .WithIdentity("trigger1", "group1")
        .WithCronSchedule("0 0 * * * ?")
        .Build();


    sched.ScheduleJob(job, trigger);

I read few articles and it contains cron expression for 12 midnight is "0 0 * * * ?"

Eg : http://blog.bobcravens.com/2009/10/an-event-based-cron-scheduled-job-in-c/

The issue is my schedule executes in every one hour... How to fix this?

like image 645
weeraa Avatar asked Oct 25 '25 14:10

weeraa


1 Answers

You are telling it to execute on every hour, the correct CRON value for midnight only is 0 0 0 * * ?

Edit: The resource you used is from 2009 so I can see how this would be wrong, for reference the current CRON is "Seconds Minutes Hours Day-of-Month Month Day-of-Week Year (optional field)"

like image 80
XerShade Avatar answered Oct 27 '25 03:10

XerShade



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!