title: Hangfire ContinueWith with multiple sources
body: <p>I am chewing on a way to accomplish the following using <strong>ContinueWith</strong>:</p>
  
  <ol>
  <li>Originating App submits a (NonConcurrent) Job</li>
  <li>Job starts up, does a little processing, calls a Web Service elsewhere</li>
  <li>Job "completes" (goes quiescent)</li>
  <li>Web Service submits a "continuation" job after it is done with its internal processing (could be 30 minutes, could be 2 days)</li>
  <li>A Jobs.ContinueWith is called somehow?</li>
  <li>Job finally completes, original job is marked as complete</li>
  </ol>
  
  <p>What I am running into is too many moving parts.  Originating App is a C#/MVC app.  User does his thing and at the end submits a long running job to be executed.  The Job Processor (C# library) does a little bit of work then calls a JAVA SOAP endpoint delivering the results of the initial processing.  The JAVA SOAP endpoint calls a COTS app to do the brunt of the processing then calls back to the job with an "I'm done".</p>
  
  <p>As you can see, I don't have a clear way to do the following:</p>
  
  <pre><code>var parentId = _jobs.Enqueue&lt;MyJob&gt;(x =&gt; x.StartExecution(job.Id));
  _jobs.ContinueWith&lt;JAVA_ENDPOINT&gt;(parentId, x =&gt; x.JAVA_EXECUTION(job.Id));  // this part is not in my control!
  _jobs.ContinueWith&lt;MyJob&gt;(parentId, x =&gt; x.ContinueExecution(job.Id));
  </code></pre>
  
  <p>I do have a REST service (POST) that I am using as the only way to start a job.  Basically, pass in a well formed payload (JSON) and the controller picks the Job object from an IoC container, decides which type of job it is (AdHoc, Recurring, Continuation, etc) then executes the proper Hangfire call(s) to Enqueue it.  The JAVA Endpoint can easily call to this REST service as well.  </p>
  
  <pre><code>[HttpPost]
  public string Post()
  {
      // safety checks removed for brevity...
      var command = new MinimumCommandModel(Request.Content.ReadAsStringAsync().Result);
      return GetPostPipeline().Handle(command).Id;
  }
  
  private static IRequestHandler&lt;MinimumCommandModel, MinimumResultModel&gt; GetPostPipeline()
  {
      return new MediatorPipeline&lt;MinimumCommandModel, MinimumResultModel&gt;
          (new QueuePostMediator()
              , new IPreRequestHandler&lt;MinimumCommandModel&gt;[]
              {
                  new PreJobLogger(),
                  new PreJobExistsValidator(),
                  new PreJobPropertiesValidator()
              }
              , new IPostRequestHandler&lt;MinimumCommandModel, MinimumResultModel&gt;[]
              {
                  new PostJobLogger()
              }
          );
  }
  </code></pre>
  
  <p>The QueuePostMediator handles the specifics of the job type (AdHoc, et al).  I am trying to write the continuation handler now and am a bit stymied by how to go about this.  I certainly don't want to do any sort of blocking actions outside of Hangfire.  I'm not sure how to "start" another job as a continuation of the original job when they are not originally connected with the parentId of the originating job.</p>
  
  <p>Basically, if I could, from inside the job, put the job on hold until an outside stimulus told hangfire to continue the job I would be golden.  I have not yet cracked how to accomplish this though.</p>
  
  <p>Thoughts?  Ideas?</p>