The Problem
I have a CakePHP application in which I call a stored procedure:
$this->FileUpload->query('exec sproc_runjob_ProcessTests', false);
This procedure picks up an uploaded file and processes it. Sometimes people upload multiple files, which calls this once for each file uploaded.
The problem is that I'm getting this error:
Database Error
Error: SQLSTATE[42000]:
[Microsoft][SQL Server Native Client 11.0][SQL Server]
SQLServerAgent Error: Request to run job ProcessTests
(from User [redacted]) refused because the job already has
a pending request from User [redacted].
SQL Query: exec sproc_runjob_ProcessTests
As far as I can tell, this means that the stored procedure can't run concurrently - I would have to run the sproc for each process serially, which would be a shame on our fancy new multi-core server.
Solutions we've thought of
Run the sproc serially
Basically the idea here is to call the stored procedure once, then ignore it's failure if it's already running. At the end of the sproc call, it would check the database to see if it needs to run again (if there are any "new" files) and run itself again if that is the case.
Don't use the existing stored procedure
This would be difficult because of time restrictions, but if someone has a good suggestion for the way we should be doing this, I'd be happy to hear it.
Thanks in advance!
Search results
Looks like this guy has the same problem, and solves it by checking the job status before calling. Perhaps I could do this from PHP before I make the sproc call?
Here's a mention of something called Service Broker. This might actually be what I'm looking for, but I'd still love any input.
Thanks in advance!