glucaci / mongodb-quartz-net

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

Problem when scheduling many jobs #29

Open Arthurrochaa opened 3 years ago

Arthurrochaa commented 3 years ago

Hi!

When trying to schedule many jobs at the same time, the following exception is bursting and consequently taking a long time to finalize the schedule:

MongoDB.Driver.Core.Operations.MongoBulkWriteOperationException em System.Private.CoreLib.dll

Follow the example of building jobs, the code snippet is inserted in a for loop, assigning the respective keys dynamically:

               var triggersAndJobs = new Dictionary<IJobDetail, IReadOnlyCollection<ITrigger>>();

                var jobBuilder = JobBuilder.Create<Scheduler>()
                    .WithIdentity(jobKey, GroupName)
                    .RequestRecovery(true))
                    .Build();

                var triggerCollection = new List<ITrigger>{ TriggerBuilder.Create()
                    .WithIdentity(triggerKey, GroupName)
                    .StartAt(time.ToUniversalTime())
                    .WithSchedule(SimpleScheduleBuilder.Create().WithMisfireHandlingInstructionFireNow())
                    .Build() };

                triggersAndJobs.Add(job, triggerCollection);

                await scheduler.ScheduleJobs(triggersAndJobs, true);