title: Hangfire: How to enqueue a job conditionally
body: <p>I am using Hangfire to trigger a database retrieval operation as a background job. </p>
  
  <p>This operation is only supposed to happen once, and can be triggered in multiple ways. (for example, in the UI whenever a user drags and drops a tool, I need to fire that job in the background. But if another tool is dragged and dropped, I don't want to fire the background job as it's already prefetched from the database). </p>
  
  <p>This is what my code looks like now:</p>
  
  <pre><code>var jobId = BackgroundJob.Enqueue&lt;BackgroundModelHelper&gt;( (x) =&gt; x.PreFetchBillingByTimePeriods(organizationId) );
  </code></pre>
  
  <p>What I want is some kind of check before I execute above statement, to find if a background job has already been fired; if yes, then do not fire another and if not, then enqueue this . </p>
  
  <p>for example:</p>
  
  <pre><code>bool prefetchIsFired = false;
  
  // find out if a background job has already been fired. If yes, set prefetchIsFired to true.
  
  if (!prefetchIsFired)
       var jobId = BackgroundJob.Enqueue&lt;BackgroundModelHelper&gt;( (x) =&gt; x.PreFetchBillingByTimePeriods(organizationId, null) );
  </code></pre>