0

I want to put together a scheduler for web data processing to limit the number of jobs, so I used the Quartz.Net framework and put that on top of IHttpAsyncHandler.

public void ProcessRequest(HttpContext context)
{
    // StdSchedulerFactory.GetDefaultScheduler().Start(); etc           
    Global.scheduler.start();

    // IJobDetail job = JobBuilder.Create<T>().WithIdentity(jobId, "Processing").Build(); etc
    Global.scheduler.AddProcessingJob<JobRxFormulas>(user, app, arguments);
}

I have passed the HttpContext into job via arguments, which works fine, but when I want to grab context.Session it is null - which makes sense as I added the processing job into it's own queue and the HttpAsyncHandler process has finished. I haven't tried, but I assume returning the result will also fail for the same reason:

context.Response.Write(json);

One idea I have is that I could declare a lock and add this loop to ProcessRequest:

while (lock);

But not sure this is the best idea.

How do I best keep the HttpContext for the handler alive so I can return the result? Or can I even return the result from the Quartz job back to ProcessRequest (like a promise in Javascript, ie $.when.then) and then send it back via context.Response?

Or would it be better to scrap Quartz completely and let HttpAsyncHandler do the job scheduling in the first place?

https://stackoverflow.com/questions/33642861/processing-job-scheduling-with-httpasynchandler

Community
  • 1
  • 1
christian.stock
  • 181
  • 2
  • 15
  • 1
    Possible duplicate of [Is there any way to gain access to an HttpContext object in a Quartz.NET job?](http://stackoverflow.com/questions/19909498/is-there-any-way-to-gain-access-to-an-httpcontext-object-in-a-quartz-net-job) – LeftyX Nov 11 '15 at 10:27
  • That doesn't really explain how to solve it though. – christian.stock Nov 11 '15 at 21:26
  • It explains really well. You can't. Even if you found a solution - as someone suggesting in the first answer - it would be dangerous as it is not thread-safe. – LeftyX Nov 12 '15 at 11:06
  • Putting a lock on ProcessRequest would work as I suggested, and that's threadsafe. I was just wondering if there are other solutions. – christian.stock Nov 12 '15 at 23:44

0 Answers0