ravendb / quartznet-RavenDB

RavenDB JobStore support for Quartz.NET scheduler.
Apache License 2.0
27 stars 19 forks source link

Trigger state is not saved to DB when exception occurs in TriggersFired method #11

Closed alainstoffels closed 7 years ago

alainstoffels commented 7 years ago

The following exception occurred while querying Triggers by Group and JobName in the TriggersFired method. This is the query that is executed when job.ConcurrentExecutionDisallowed is true.

2017-01-28 15:23:02.8673|Quartz.Core.QuartzSchedulerThread|Error|Runtime error occurred in main trigger firing loop. System.TimeoutException: Waited for 27,407ms for the query to return non stale result. at Raven.Client.Document.SessionOperations.QueryOperation.IsAcceptable(QueryResult result) at Raven.Client.Document.AbstractDocumentQuery2.ExecuteActualQuery() at Raven.Client.Document.AbstractDocumentQuery2.InitSync() at Raven.Client.Document.AbstractDocumentQuery2.get_QueryResult() at Raven.Client.Linq.RavenQueryProviderProcessor1.ExecuteQuery[TProjection]() at Raven.Client.Linq.RavenQueryProviderProcessor1.Execute(Expression expression) at Raven.Client.Linq.RavenQueryProvider1.Execute(Expression expression) at Raven.Client.Linq.RavenQueryProvider1.System.Linq.IQueryProvider.Execute(Expression expression) at Raven.Client.Linq.RavenQueryInspector1.GetEnumerator() at Quartz.Impl.RavenDB.RavenJobStore.TriggersFired(IList`1 triggers) at Quartz.Core.QuartzSchedulerThread.Run()

Because of this, session.SaveChanges() is not called, and the state of the respective trigger stays 'Acquired' rather than 'Waiting'. The AcquireNextTriggers method queries triggers having the 'Waiting' state. Because the trigger still has the 'Acquired' state in our DB, it is never triggered again until you edit it in the database or restart the application.

My suggestion is to wrap the code inside the TriggersFired method with a try block and call session.SaveChanges() in the finally block. I will create a PR for this.

alainstoffels commented 7 years ago

Created a PR: #12