glucaci / mongodb-quartz-net

MongoDB Job Store for Quartz.NET
MIT License
50 stars 39 forks source link

"End time cannot be before start time" from Quartz during getting trigger that have EndTime in past #33

Closed YauheniKokhna closed 7 months ago

YauheniKokhna commented 2 years ago

I am using Quartz.NET. and Quartz.Spi.MongoDbJobStore v 3.1.0 I run into the following issue: imagine Job that have triggers in past. To be more specific: today is 1/20/2022, so lets say trigger StartTime 2021-12-27 01:00:00.000Z EndTime 2021-12-27 01:00:00.000Z NextFireTime 2021-12-27 01:00:00.000Z This case is possible if for some reason my server was turned off (or down) at the time the trigger should fire. Once I turn the server on back (after EndTime 2021-12-27 01:00:00.000Z) I want Quartz puck up the missed trigger and fire it right away. So Quartz.Spi.MongoDbJobStore calls Quartz.Spi.MongoDbJobStore.Models.CalendarIntervalTrigger.GetTrigger() (for Cron triggers there is similar flow) The method creates new CalendarIntervalTrigger() and then tries to FillTrigger(). image As we see StartTime for new CalendarIntervalTrigger is not provided. So by default Quartz thru getter returns SystemTime.UtcNow() - let it be as of today 2022-01-22 03:55:00.000Z image Later when in FillTrigger() we assign EndTime (which is 2021-12-27 01:00:00.000Z) before we assing StartTime (2022-01-22 03:55:00.000Z) image then Quartz throws an exception with message "End time cannot be before start time" because of the logic it has in setter image

So in FillTrigger() we need assign first StartTime then EndTime

glucaci commented 7 months ago

Fixed with 4.0.0-preview.2