raisedapp / Hangfire.Storage.SQLite

An Alternative SQLite Storage for Hangfire
https://www.nuget.org/packages/Hangfire.Storage.SQLite
MIT License
155 stars 31 forks source link

The given key 'SucceededAt' was not present in the dictionary #17

Closed CesarStatik closed 4 years ago

CesarStatik commented 4 years ago

I am getting this error while looking at the dashboad for the jobs that have been completed.

In the code I am doing something simple:

BackgroundJob.Enqueue(() => System.Console.WriteLine($"Hello world"));

{ "error": { "code": "ExceptionErrorCode", "message": "The given key 'SucceededAt' was not present in the dictionary.", "target": "System.Collections.Generic.KeyNotFoundException", "details": [ { "code": "ExceptionStacktraceErrorCode", "message": " at System.Collections.Generic.Dictionary2.get_Item(TKey key)\r\n at Hangfire.Storage.SQLite.SQLiteMonitoringApi.<>c.<SucceededJobs>b__33_1(JobDetailedDto sqlJob, Job job, Dictionary2 stateData)\r\n at Hangfire.Storage.SQLite.SQLiteMonitoringApi.DeserializeJobs[TDto](ICollection1 jobs, Func4 selector)\r\n at Hangfire.Storage.SQLite.SQLiteMonitoringApi.<>c__DisplayClass33_0.b__0(HangfireDbContext connection)\r\n at Hangfire.Dashboard.Pages.SucceededJobs.Execute()\r\n at Hangfire.Dashboard.RazorPage.TransformText(String body)\r\n at Hangfire.Dashboard.RazorPageDispatcher.Dispatch(DashboardContext context)\r\n at Hangfire.Dashboard.AspNetCoreDashboardMiddleware.Invoke(HttpContext httpContext)\r\n at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context)\r\n at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)\r\n at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)\r\n at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIIndexMiddleware.Invoke(HttpContext httpContext)\r\n at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext)\r\n at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context)\r\n at Enstoa.Application.Core.AspNetCore.Errors.ErrorHandlerMiddleware.Invoke(HttpContext context, ILogger`1 logger, IHostingEnvironment env)", "details": [] } ] } }

felixclase commented 4 years ago

Hi,

Please try again with version 0.2.4 and let me know the result.

CesarStatik commented 4 years ago

It worked for that page but now if I click on the job details I get the following error, not sure if I should open a new issue, it looks similar but it appears to be present in a different part of code.

{ "error": { "code": "ExceptionErrorCode", "message": "The given key 'Queue' was not present in the dictionary.", "target": "System.Collections.Generic.KeyNotFoundException", "details": [ { "code": "ExceptionStacktraceErrorCode", "message": " at System.Collections.Generic.Dictionary2.get_Item(TKey key)\r\n at Hangfire.Dashboard.JobHistoryRenderer.EnqueuedRenderer(HtmlHelper helper, IDictionary2 stateData)\r\n at Hangfire.Dashboard.Pages.JobDetailsPage.Execute()\r\n at Hangfire.Dashboard.RazorPage.TransformText(String body)\r\n at Hangfire.Dashboard.RazorPageDispatcher.Dispatch(DashboardContext context)\r\n at Hangfire.Dashboard.AspNetCoreDashboardMiddleware.Invoke(HttpContext httpContext)\r\n at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context)\r\n at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)\r\n at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)\r\n at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIIndexMiddleware.Invoke(HttpContext httpContext)\r\n at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext)\r\n at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context)\r\n at Enstoa.Application.Core.AspNetCore.Errors.ErrorHandlerMiddleware.Invoke(HttpContext context, ILogger`1 logger, IHostingEnvironment env)", "details": [] } ] } }

felixclase commented 4 years ago

OS? Version of Hangfire.Storage.SQLite?

CesarStatik commented 4 years ago

OS? Version of Hangfire.Storage.SQLite?

OS: Windows 10 Pro 1909 Version of Hangfire.Storage.SQLite: 0.2.4

felixclase commented 4 years ago

You could delete the Hangfire.db file that is created by default and try again.

I find the error strange.

CesarStatik commented 4 years ago

I deleted the DB and ran the solution again and ran the job, it was executed successfully and I can see the Job in the page "/hangfire/jobs/succeeded" but as soon as I click on the job Id "/hangfire/jobs/details/1" this error occurs

{ "error": { "code": "ExceptionErrorCode", "message": "The given key 'Queue' was not present in the dictionary.", "target": "System.Collections.Generic.KeyNotFoundException", "details": [ { "code": "ExceptionStacktraceErrorCode", "message": " at System.Collections.Generic.Dictionary2.get_Item(TKey key)\r\n at Hangfire.Dashboard.JobHistoryRenderer.EnqueuedRenderer(HtmlHelper helper, IDictionary2 stateData)\r\n at Hangfire.Dashboard.Pages.JobDetailsPage.Execute()\r\n at Hangfire.Dashboard.RazorPage.TransformText(String body)\r\n at Hangfire.Dashboard.RazorPageDispatcher.Dispatch(DashboardContext context)\r\n at Hangfire.Dashboard.AspNetCoreDashboardMiddleware.Invoke(HttpContext httpContext)\r\n at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context)\r\n at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)\r\n at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)\r\n at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIIndexMiddleware.Invoke(HttpContext httpContext)\r\n at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext)\r\n at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context)\r\n at Enstoa.Application.Core.AspNetCore.Errors.ErrorHandlerMiddleware.Invoke(HttpContext context, ILogger`1 logger, IHostingEnvironment env)", "details": [] } ] } }

felixclase commented 4 years ago

Could you share the code?

CesarStatik commented 4 years ago

Let me create a new solution and see if I can replicate there and then I can share

CesarStatik commented 4 years ago

I think the issue is rather on the "Hangfire.Dashboard.JobHistoryRenderer.EnqueuedRenderer" class, I just looked at the code "https://github.com/HangfireIO/Hangfire/blob/master/src/Hangfire.Core/Dashboard/JobHistoryRenderer.cs" and in the line 232 the are accessing the dictionary without checking if the key exist. I think this issue can be closed here.

CesarStatik commented 4 years ago

Hi Felix,

I noticed that the issue still exist for the functions "ScheduledJobs", "ProcessingJobs" and "FailedJobs" on the "SQLiteMonitoringApi"class, It seems that you missed adding validations on "ExceptionDetails", "ExceptionMessage" and "ExceptionType" in the "FailedJobs" function, "StartedAt" in the "ProcessingJobs" function and "ScheduledAt" in the "ScheduledJobs" function.

Can you please include this validations?