Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, have you had a chance to look at service broker? From your description, it sounds like that's what you actually want. </p> <p>The difference would be instead of starting a job, you put your data into a SB queue and SB will call your processing proc asynchronously and completely side-step issues with already-running jobs etc. It will auto spawn/terminate additional threads and demand dictates, it takes care of order etc. </p> <p>Here's a good (and vaguely related) tutorial. <a href="http://www.sqlteam.com/article/centralized-asynchronous-auditing-with-service-broker" rel="nofollow">http://www.sqlteam.com/article/centralized-asynchronous-auditing-with-service-broker</a></p> <p>Let's assume that you can't use SB for whatever reason (but seriously, do!).</p> <p>What about using the job spid's context_info. </p> <ol> <li>Your job calls a wrapper proc that execs each step individually.</li> <li><p>The first statement inside the wrapper proc is </p> <pre><code>DECLARE @context_info VARBINARY(30) SET @context_info = CAST('MyJob1' AS VARBINARY) SET CONTEXT_INFO @context_info </code></pre></li> <li><p>When your proc finishes (or in your catch block) </p> <pre><code>SET CONTEXT_INFO 0x0 </code></pre></li> <li><p>When you are looking at calling your job, do this:</p> <pre><code>IF NOT EXISTS (SELECT * FROM master..sysprocesses WITH (NOLOCK) WHERE context_info=CAST('MyJob1' AS VARBINARY)) EXEC StartJob </code></pre></li> </ol> <p>When your wrapper proc terminates or the connection is closed, your context_info goes away. </p> <p>You could also use a global temp table (i.e. ##JobStatus) They will disappear when all spids that reference it disconnect or if it's explicitly dropped. </p> <p>Just a few thoughts.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload