question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DateTimeOffset stored as ISO 8601 string in JobDataMap is discarded when executing the job

See original GitHub issue

Version: 3.0.7

  • dotnetcore 3.1.200

Expected behavior

When storing a DateTimeOffset (ISO 8601) string in the JobDataMap and having it serialised into a ADO Store. I expect to be able to retrieve the DateTimeOffset from the job context when the job executes.

The following config is set (as well as the ADO store details):

  • quartz.jobStore.useProperties = true
  • quartz.serializer.type = json

Actual behavior

I am unable to get the DateTimeOffset (ISO 8601) string from the MergedJobDataMap associated with the job execution context. I need to prefix the string value with something else to be able to retrieve it. It is stored in the database, but when pulling it into the executing job it’s not there.

My shot in the dark guess is that the deserialiser is picking up that the string is a DateTimeOffset and is thus deserialising it into that type whereas JobDataMap is expecting all values to be strings (due to the useProperties config) and quietly discards anything which is not.

Steps to reproduce

  1. Set the quartz.jobStore.useProperties = true value in config
  2. Set the quartz.serializer.type = json value in config
  3. Create a new job/trigger with at least one DateTimeOffset stored as a string using the ISO 8601 format.
var job = JobBuilder.Create<ExampleJob>()
			.WithIdentity("Example", group)				
                         .UsingJobData("executed_at", DateTimeOffset.Now.ToString("O"))
                         .Build();

var jobTrigger = TriggerBuilder.Create()
				.WithIdentity("ExampleTrigger", group)
				.StartNow()
				.Build();
  1. Now schedule the job. When it gets executed the IJobExecutionContext will not have the executed_at property defined in the MergedJobDataMap.

If I store the DateTimeOffset like this, then I can retrieve it as a string and parse it myself:

 .UsingJobData("executed_at", $"{nameof(DateTimeOffset)}:{DateTimeOffset.Now:O}")

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
olicoopercommented, Apr 19, 2020

Hey @dmk99 If you want to use the fix for this now, you can use the preview/nightly version of the library which can be found at this MyGet Feed

If this doesn’t fix your issue then let me know and I’ll try to see why if I can 👍

0reactions
olicoopercommented, Apr 22, 2020

I believe quartz.jobStore.useProperties = true instructs Quartz to store and retrieve all values as strings instead of trying to serialize and deserialize the object (see code below). The reason this is the recommended option is that it is unlikely to break when Quartz knows all values are simple strings, but I think it is also safe to use primitive types and have this option set to false. As long as you avoid using classes then you’ll probably be safe.

https://github.com/quartznet/quartznet/blob/b76e6fa5f03d333b94be00f829493dca3f2480d8/src/Quartz/Impl/AdoJobStore/StdAdoDelegate.cs#L3254-L3256

Read more comments on GitHub >

github_iconTop Results From Across the Web

DateTime and DateTimeOffset support in System.Text.Json
The System.Text.Json library parses and writes DateTime and DateTimeOffset values according to the ISO 8601-1:2019 extended profile.
Read more >
System.FormatException: The JSON value is not in a ...
Implementing custon JSON behaviours with System.Text. ... something not in the default ISO 8601-1:2019 format you need to roll your own.
Read more >
worldofsea/quartznet
Jobs and plugins are now in a separate assemblies/NuGet packages Quartz. ... Fix JobDataMap dirty flag when constructing from existing map (#431); Store...
Read more >
Neuron 3.7.5.721
date format on the computer the Neuron solution was last saved in, and that solution ... //Get the connection string from Job Data...
Read more >
Windows Azure and Cloud Computing Posts for 1/21/2013+
In this release, backup to Windows Azure Blob storage is supported using T-SQL and SMO. SQL Server Databases on an on premises instance...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found