How to get executing job's name?

ds99jove picture ds99jove · Jan 17, 2011 · Viewed 12k times · Source

In my application I have a static class (singleton) that needs to be initialized with some environmental variables that's used through out my layers, I'm calling it my applicationContext. That in turn has customer and user contexts.

As each job runs it modifies these customer and user contexts depending on the situation. The problem I have is that when 2 jobs fires concurrently they might overwrite each others contexts, therefor I need to keep multiple user and customer contexts alive for each running job and I need to be able to pick the right context by somehow being able to see what the current job is.

Is it possible to somehow get information about the current executing quartz.net job?

I'm envisioning something like this where "currentQuartzJob.Name" is made up and is the part I'm missing:

public class MyContextImpl : IApplicationContext {
private Dictionary<string,subContexts> allCustomerContexts;
public string CurrentContext
{
    get { return allCustomerContexts[currentQuartzJob.Name] };
}

}

edit:

I don't think it's possible to do what I wanted, that is to be able to get the executing job's name in a class that doesn't know about Quartz.Net.

What I really needed was a way to keep a different context for each job. I managed to do that by looking at the executing thread's ID as they seem to differ for each running job.

Answer

Andrew Usikov picture Andrew Usikov · May 2, 2013

Try this:

public void Execute(IJobExecutionContext context)
{
    var yourJobName = context.JobDetail.Key.Name;
}