Mixed datetime formats at [HangFire].[State], Data column

108 Views Asked by At

I recently joined a project that is using hangfire 1.6.20. We are having some problems with our code, and I decided to enable hangfire dashboards to help me check what is gong on. I am getting some exceptions if I move to the 2nd page of the failures. When debugging I find out that the reason is due to different datetime formats in my database:

The query I ran:

select top 1000 s.data from [HangFire].[Job] j
    join [HangFire].[State] s on j.StateId = s.Id
where j.StateName = 'Failed'

The resuts

{"FailedAt":"2022-11-30T15:34:13.7419289Z","ExceptionType":"..."}
{"FailedAt":"1669822299229","ExceptionType":"..."}

The 1st row works, the 2nd not. The most recent records looked all good and using the 1st line format, but old ones not.

Any idea what caused this difference in datetime format? Any other DI registration that affects hangfire? I believe there was a change in infrastructure, could infra affect this, maybe PCs in different regions. Can this potentially affect this?

Thank you

I already search through code, but cannot find Newtwonsoft registrations that could potentially affect this. Checked git history and deployments to understand if there were significant changes, but no luck yet.

Edited

Found this github issue that seems that describes the problem: https://github.com/HangfireIO/Hangfire/issues/2183

Scipt for fixing

Please keep in mind that you should first check the amount of records you will update to not overload the server!

update [HangFire].[State]
set data = JSON_MODIFY(data, '$.FailedAt', 
                CONVERT(VARCHAR(33), 
                    DATEADD(ms, 
                        cast(JSON_VALUE (data, '$.FailedAt') as bigint) % 1000, DATEADD(SECOND, cast(JSON_VALUE (data, '$.FailedAt') as bigint) / 1000, '19700101'))
                    , 126)
            )
where data like '{"FailedAt":"16%'
    or data like '{"FailedAt":"15%'
0

There are 0 best solutions below