Nanoko / quartznet-mongodb

MongoDB provider for Quartz.NET
41 stars 31 forks source link

Priority Triggers #1

Closed wzinc closed 12 years ago

wzinc commented 12 years ago

Hi, I've been working with your quartznet-mongodb bridge. It's very fast, and I'm really happy with it. I noticed that it doesn't pay attention to priorities, though. I found that by adding only two lines of code, I was able to fix that.

Here are those changes:

Add the priority to the TriggerState collection in StoreTrigger JobStore.cs:507:

533: triggerState.Add("Priority", newTrigger.Priority); // <---

And, in AcquireNextTriggers JobStore.cs:1358, replace 1382:

1382: //TriggerStates.Update(Query.EQ("State", "Waiting"), Update.Set("InstanceId", _instanceID).Set("State", "Locked"));
1382: TriggerStates.FindAndModify(Query.EQ("State", "Waiting"), SortBy.Descending("Priority").Ascending("NextFireTimeUtc"), Update.Set("InstanceId", _instanceID).Set("State", "Locked"));

That should do it; I'm pretty new to Mongo, so there may be a more efficient way. Anyway, thanks for a great adapter.

Nanoko commented 12 years ago

Hi, thanks for your feedback. I consider your changes but need to rewrite it differently due to other evolutions in my version. This will be commited as soon as tested.

Nanoko commented 12 years ago

Part of v1.1 changes : trigger acquisition now ordered by ascending fire time then by descending priority

wzinc commented 12 years ago

Thank you.