JobDataMap update AFTER job fires - Where can it be done?

70 views
Skip to first unread message

Marty Wasznicky

unread,
Mar 10, 2020, 4:47:22 PM3/10/20
to Quartz.NET
Hi,

I know I can update the job data map values within the custom Job class.  However, is it possible to update it within the Job Factory AFTER its been fired....or somewhere else...maybe in an event?

Marko Lahma

unread,
Mar 10, 2020, 4:53:39 PM3/10/20
to Quartz. NET

So what's the actual use case, like the difference between having map updates as last lines of job logic? Or do you just want to update the job definition at any point of time?

-Marko


On Tue, Mar 10, 2020, 22:47 Marty Wasznicky <marty.w...@neudesic.com> wrote:
Hi,

I know I can update the job data map values within the custom Job class.  However, is it possible to update it within the Job Factory AFTER its been fired....or somewhere else...maybe in an event?

--
You received this message because you are subscribed to the Google Groups "Quartz.NET" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quartznet+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/quartznet/f0201aac-b165-4ffd-b0ac-52c85bd65b7e%40googlegroups.com.

Marty Wasznicky

unread,
Mar 10, 2020, 5:10:45 PM3/10/20
to Quartz.NET
Hi Marko,

I have a custom job interface called iPeregrineJob. I want users to be able to implement their own jobs..as long as they implement my interface. The Idea is that I don't necessarily want them to know how quartz.net jobs work...to use it. In the job factory, I'm taking the job data map, and transferring the collection of name values to a serializable dictionary...and then passing the serializable dictionary to the Peregrine Job class as property. this dictionary gets passed to their internal implementation....in our case a process designer, where a user has the ability to access and modify the dictionary.

Hence, after the job executes, I'd like to handle the updating of the job data map with any new or updated values from the Dictionary...outside of the Peregrine Job class so the user doesn't have to deal with it. 

does that make sense?


On Tuesday, March 10, 2020 at 1:53:39 PM UTC-7, Marko Lahma wrote:

So what's the actual use case, like the difference between having map updates as last lines of job logic? Or do you just want to update the job definition at any point of time?

-Marko


On Tue, Mar 10, 2020, 22:47 Marty Wasznicky <marty.w...@neudesic.com> wrote:
Hi,

I know I can update the job data map values within the custom Job class.  However, is it possible to update it within the Job Factory AFTER its been fired....or somewhere else...maybe in an event?

--
You received this message because you are subscribed to the Google Groups "Quartz.NET" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quar...@googlegroups.com.

Marko Lahma

unread,
Mar 10, 2020, 5:25:06 PM3/10/20
to Quartz. NET

Well if you want such indirection I think you could get away with having just a job that has the target type to instantiate, create the instance,  transform new map from own map and then after your interface contract execute transfer the map back to Quartz map. So standard persistence would still apply using these two slots.

You can also utilize trigger map to reuse job logic if it suits you.

Just make sure you have good serialization format like JSON and probably assembly qualified type references without versions.

-Marko

To unsubscribe from this group and stop receiving emails from it, send an email to quartznet+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/quartznet/ec5eb3fe-b917-478b-914c-5a78a1914401%40googlegroups.com.

Marty Wasznicky

unread,
Mar 10, 2020, 5:35:41 PM3/10/20
to Quartz.NET
Hi Marko,

I actually just figured out how I could update the job data map from the dictionary outside of the job class....within the factory (or kind of).  In the job factory...I add a global Job listener. I then setup the JobWasExecuted method like so:

public Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken = default(CancellationToken))
        {
            var job = context.JobInstance as IPeregrineJob;

            var dataMap = context.JobDetail.JobDataMap;
            foreach (var key in dataMap.GetKeys())
            {
                if (job.JobDataDictionary.ContainsKey(key))
                    dataMap[key] = job.JobDataDictionary[key];
            }

            return Task.CompletedTask;
        }

That seemed to do the trick.  do you see any issues with this?

also...another question.  is the custom Job Factories essentially singleton objects for the scheduler?  Or should I consider implementing locking on the resources I'm using?

Marko Lahma

unread,
Mar 10, 2020, 5:43:58 PM3/10/20
to Quartz. NET

At a glance one possible problem could be custom job overwriting your handler job's values if there are any such configuration entries as there is no separation. 

Custom jobs seem quite coupled to Quartz - client code could "cast itself" to IJob. Don't know if it's an issue. Prototyping and testing will probably tell. 

Job factory is expected to be a singleton.

-Marko

To unsubscribe from this group and stop receiving emails from it, send an email to quartznet+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/quartznet/a95c463a-4231-4e21-9fd3-168f8391b592%40googlegroups.com.

Marty Wasznicky

unread,
Mar 10, 2020, 6:05:25 PM3/10/20
to Quartz.NET
Excellent!
Reply all
Reply to author
Forward
0 new messages