IoTSharp / SilkierQuartz

SilkierQuartz can host jobs using HostService and Provide a web management tools for Quartz !
http://sq.iotsharp.io/
MIT License
357 stars 71 forks source link

BUG - NullReferenceException on SilkierQuartz.Controllers.JobsController.AdditionalData #130

Closed scott-mac closed 2 years ago

scott-mac commented 2 years ago

This took a little more finagling than the samples but I was able to get it working and the UI coming up, but I'm on .NET Core 3.1 and that seems to be par for the course on a lot of packages ;)

The issue I was running into was anytime I would click on Jobs or Triggers there'd be a NullReferenceException thrown out of System.Runtime.CompilerServices.AsyncStateMachineBox. Digging into this I was able to trace it to:


 This exception was originally thrown at this call stack:
    SilkierQuartz.Controllers.JobsController.AdditionalData()
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in ExceptionDispatchInfo.cs
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) in TaskAwaiter.cs
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) in TaskAwaiter.cs
    System.Runtime.CompilerServices.TaskAwaiter<TResult>.GetResult() in TaskAwaiter.cs
    Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultTypeMapper, Microsoft.Extensions.Internal.ObjectMethodExecutor, object, object[]) in ActionMethodExecutor.cs

specifically this line:

var history = await Scheduler.Context.GetExecutionHistoryStore().FilterLastOfEveryJob(10);

That call to GetExecutionHistory I suspect is the culprit returning null. By default the history plugin is not enabled, but once I was able to figure out how to add it in my startup, the NullReference went away. If anyone else comes across this, here's what I did:

Installed these packages:

Quartz.Plugins SilkierQuartz.Plugins.RecentHistory

Then you register the history plugin using the properties of the Quartz.SchedulerBuilder and the error vanishes.

 public async Task<IScheduler> GetScheduler(string connString) {
    System.Collections.Specialized.NameValueCollection nvc = new System.Collections.Specialized.NameValueCollection();
    nvc.Add("quartz.plugin.recentHistory.type", "Quartz.Plugins.RecentHistory.ExecutionHistoryPlugin, Quartz.Plugins.RecentHistory");
    nvc.Add("quartz.plugin.recentHistory.storeType", "Quartz.Plugins.RecentHistory.Impl.InProcExecutionHistoryStore, Quartz.Plugins.RecentHistory");
    var schedBuilder = SchedulerBuilder.Create();
    schedBuilder.Properties.Add(nvc);
    schedBuilder.UsePersistentStore(x => {
     x.UseProperties = true;
     x.UseSqlServer(connString);
     x.UseJsonSerializer();
     });

    var sched = await schedBuilder.BuildScheduler();

    await sched.Start();

    return sched;
}
maikebing commented 2 years ago

I cannot reproduce this question

maikebing commented 2 years ago

fixed