docs/agenda/2.0.0/Job.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Job - Documentation
</title>
<link href="https://www.braintreepayments.com/images/favicon-ccda0b14.png" rel="icon" type="image/png">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.7.2/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<!-- start Mixpanel -->
<script type="text/javascript">(function(e,a){if(!a.__SV){var b=window;try{var c,l,i,j=b.location,g=j.hash;c=function(a,b){return(l=a.match(RegExp(b+"=([^&]*)")))?l[1]:null};g&&c(g,"state")&&(i=JSON.parse(decodeURIComponent(c(g,"state"))),"mpeditor"===i.action&&(b.sessionStorage.setItem("_mpcehash",g),history.replaceState(i.desiredHash||"",e.title,j.pathname+j.search)))}catch(m){}var k,h;window.mixpanel=a;a._i=[];a.init=function(b,c,f){function e(b,a){var c=a.split(".");2==c.length&&(b=b[c[0]],a=c[1]);b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments,
0)))}}var d=a;"undefined"!==typeof f?d=a[f]=[]:f="mixpanel";d.people=d.people||[];d.toString=function(b){var a="mixpanel";"mixpanel"!==f&&(a+="."+f);b||(a+=" (stub)");return a};d.people.toString=function(){return d.toString(1)+".people (stub)"};k="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
for(h=0;h<k.length;h++)e(d,k[h]);a._i.push([b,c,f])};a.__SV=1.2;b=e.createElement("script");b.type="text/javascript";b.async=!0;b.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";c=e.getElementsByTagName("script")[0];c.parentNode.insertBefore(b,c)}})(document,window.mixpanel||[]);
mixpanel.init("1919205b2da72e4da3b9b6639b444d59");</script>
<!-- end Mixpanel -->
</head>
<body>
<svg style="display: none;">
<defs>
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
</symbol>
</defs>
</svg>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<div class="top-nav-wrapper">
<ul>
<li >
<a href="index.html">
<svg fill="#6D6D6D" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>
</a>
</li>
</ul>
</div>
<nav>
<h3 class="reference-title">
Agenda
</h3>
<h3>Classes</h3><ul><li id="Agenda-nav"><a href="Agenda.html">Agenda</a><ul class='methods'><li data-type="method" id="Agenda-cancel-nav"><a href="Agenda.html#cancel">cancel</a></li><li data-type="method" id="Agenda-create-nav"><a href="Agenda.html#create">create</a></li><li data-type="method" id="Agenda-database-nav"><a href="Agenda.html#database">database</a></li><li data-type="method" id="Agenda-dbInit-nav"><a href="Agenda.html#dbInit">dbInit</a></li><li data-type="method" id="Agenda-defaultConcurrency-nav"><a href="Agenda.html#defaultConcurrency">defaultConcurrency</a></li><li data-type="method" id="Agenda-defaultLockLifetime-nav"><a href="Agenda.html#defaultLockLifetime">defaultLockLifetime</a></li><li data-type="method" id="Agenda-defaultLockLimit-nav"><a href="Agenda.html#defaultLockLimit">defaultLockLimit</a></li><li data-type="method" id="Agenda-define-nav"><a href="Agenda.html#define">define</a></li><li data-type="method" id="Agenda-every-nav"><a href="Agenda.html#every">every</a></li><li data-type="method" id="Agenda-findAndLockNextJob-nav"><a href="Agenda.html#findAndLockNextJob">findAndLockNextJob</a></li><li data-type="method" id="Agenda-jobs-nav"><a href="Agenda.html#jobs">jobs</a></li><li data-type="method" id="Agenda-locklimit-nav"><a href="Agenda.html#locklimit">locklimit</a></li><li data-type="method" id="Agenda-maxConcurrency-nav"><a href="Agenda.html#maxConcurrency">maxConcurrency</a></li><li data-type="method" id="Agenda-mongo-nav"><a href="Agenda.html#mongo">mongo</a></li><li data-type="method" id="Agenda-name-nav"><a href="Agenda.html#name">name</a></li><li data-type="method" id="Agenda-now-nav"><a href="Agenda.html#now">now</a></li><li data-type="method" id="Agenda-processEvery-nav"><a href="Agenda.html#processEvery">processEvery</a></li><li data-type="method" id="Agenda-purge-nav"><a href="Agenda.html#purge">purge</a></li><li data-type="method" id="Agenda-saveJob-nav"><a href="Agenda.html#saveJob">saveJob</a></li><li data-type="method" id="Agenda-schedule-nav"><a href="Agenda.html#schedule">schedule</a></li><li data-type="method" id="Agenda-sort-nav"><a href="Agenda.html#sort">sort</a></li><li data-type="method" id="Agenda-start-nav"><a href="Agenda.html#start">start</a></li><li data-type="method" id="Agenda-stop-nav"><a href="Agenda.html#stop">stop</a></li></ul></li><li id="Job-nav"><a href="Job.html">Job</a><ul class='methods'><li data-type="method" id="Job-computeNextRunAt-nav"><a href="Job.html#computeNextRunAt">computeNextRunAt</a></li><li data-type="method" id="Job-disable-nav"><a href="Job.html#disable">disable</a></li><li data-type="method" id="Job-enable-nav"><a href="Job.html#enable">enable</a></li><li data-type="method" id="Job-fail-nav"><a href="Job.html#fail">fail</a></li><li data-type="method" id="Job-isRunning-nav"><a href="Job.html#isRunning">isRunning</a></li><li data-type="method" id="Job-priority-nav"><a href="Job.html#priority">priority</a></li><li data-type="method" id="Job-remove-nav"><a href="Job.html#remove">remove</a></li><li data-type="method" id="Job-repeatAt-nav"><a href="Job.html#repeatAt">repeatAt</a></li><li data-type="method" id="Job-repeatEvery-nav"><a href="Job.html#repeatEvery">repeatEvery</a></li><li data-type="method" id="Job-run-nav"><a href="Job.html#run">run</a></li><li data-type="method" id="Job-schedule-nav"><a href="Job.html#schedule">schedule</a></li><li data-type="method" id="Job-toJSON-nav"><a href="Job.html#toJSON">toJSON</a></li><li data-type="method" id="Job-touch-nav"><a href="Job.html#touch">touch</a></li><li data-type="method" id="Job-unique-nav"><a href="Job.html#unique">unique</a></li></ul></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#parsePriority">parsePriority</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">
Job
</h1>
<section>
<header>
<h2>
Job
</h2>
</header>
<article>
<div class="container-overview">
<span class='name-container'>
<a class="link-icon" href="#Job">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="Job">
<span class="type-signature"></span>new Job<span class="signature">(args)</span><span class="type-signature"></span>
</h4>
</span>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">
Object
</span>
</td>
<td class="description last">
</td>
</tr>
</tbody>
</table>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>agenda</code></td>
<td class="type">
<span class="param-type">
Object
</span>
</td>
<td class="description last">
<p>The Agenda instance</p>
</td>
</tr>
<tr>
<td class="name"><code>attrs</code></td>
<td class="type">
<span class="param-type">
Object
</span>
</td>
<td class="description last">
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="job_index.js.html">job/index.js</a>, <a href="job_index.js.html#line28">line 28</a>
</li>
</ul>
</dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<span class='name-container'>
<a class="link-icon" href="#computeNextRunAt">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="computeNextRunAt">
<span class="type-signature"></span>computeNextRunAt<span class="signature">()</span><span class="type-signature"> → {exports}</span>
</h4>
</span>
<div class="description">
<p>Internal method used to compute next time a job should run and sets the proper values</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="job_compute-next-run-at.js.html">job/compute-next-run-at.js</a>, <a href="job_compute-next-run-at.js.html#line8">line 8</a>
</li>
</ul>
</dd>
</dl>
<span class='name-container'>
<a class="link-icon" href="#disable">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="disable">
<span class="type-signature"></span>disable<span class="signature">()</span><span class="type-signature"> → {exports}</span>
</h4>
</span>
<div class="description">
<p>Prevents the job type from running</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="job_disable.js.html">job/disable.js</a>, <a href="job_disable.js.html#line3">line 3</a>
</li>
</ul>
</dd>
</dl>
<span class='name-container'>
<a class="link-icon" href="#enable">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="enable">
<span class="type-signature"></span>enable<span class="signature">()</span><span class="type-signature"> → {<a href="Job.html">Job</a>}</span>
</h4>
</span>
<div class="description">
<p>Allows job type to run</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="job_enable.js.html">job/enable.js</a>, <a href="job_enable.js.html#line3">line 3</a>
</li>
</ul>
</dd>
</dl>
<span class='name-container'>
<a class="link-icon" href="#fail">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="fail">
<span class="type-signature"></span>fail<span class="signature">(reason)</span><span class="type-signature"> → {exports}</span>
</h4>
</span>
<div class="description">
<p>Fails the job with a reason (error) specified</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>reason</code></td>
<td class="type">
<span class="param-type">
Error
</span>
|
<span class="param-type">
String
</span>
</td>
<td class="description last">
<p>reason job failed</p>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="job_fail.js.html">job/fail.js</a>, <a href="job_fail.js.html#line4">line 4</a>
</li>
</ul>
</dd>
</dl>
<span class='name-container'>
<a class="link-icon" href="#isRunning">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="isRunning">
<span class="type-signature"></span>isRunning<span class="signature">()</span><span class="type-signature"> → {Boolean}</span>
</h4>
</span>
<div class="description">
<p>A job is running if:
(lastRunAt exists AND lastFinishedAt does not exist)
OR
(lastRunAt exists AND lastFinishedAt exists but the lastRunAt is newer [in time] than lastFinishedAt)</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="job_is-running.js.html">job/is-running.js</a>, <a href="job_is-running.js.html#line3">line 3</a>
</li>
</ul>
</dd>
</dl>
<span class='name-container'>
<a class="link-icon" href="#priority">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="priority">
<span class="type-signature"></span>priority<span class="signature">(priority)</span><span class="type-signature"> → {Number}</span>
</h4>
</span>
<div class="description">
<p>Internal method to turn priority into a number</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>priority</code></td>
<td class="type">
<span class="param-type">
String
</span>
|
<span class="param-type">
Number
</span>
</td>
<td class="description last">
<p>string to parse into number</p>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="job_priority.js.html">job/priority.js</a>, <a href="job_priority.js.html#line3">line 3</a>
</li>
</ul>
</dd>
</dl>
<span class='name-container'>
<a class="link-icon" href="#remove">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="remove">
<span class="type-signature"></span>remove<span class="signature">()</span><span class="type-signature"> → {Promise}</span>
</h4>
</span>
<div class="description">
<p>Remove the job from MongoDB</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="job_remove.js.html">job/remove.js</a>, <a href="job_remove.js.html#line3">line 3</a>
</li>
</ul>
</dd>
</dl>
<span class='name-container'>
<a class="link-icon" href="#repeatAt">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="repeatAt">
<span class="type-signature"></span>repeatAt<span class="signature">(time)</span><span class="type-signature"> → {exports}</span>
</h4>
</span>
<div class="description">
<p>Sets a job to repeat at a specific time</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>time</code></td>
<td class="type">
<span class="param-type">
String
</span>
</td>
<td class="description last">
<p>time to repeat job at (human readable or number)</p>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="job_repeat-at.js.html">job/repeat-at.js</a>, <a href="job_repeat-at.js.html#line3">line 3</a>
</li>
</ul>
</dd>
</dl>
<span class='name-container'>
<a class="link-icon" href="#repeatEvery">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="repeatEvery">
<span class="type-signature"></span>repeatEvery<span class="signature">(interval, options)</span><span class="type-signature"> → {<a href="Job.html">Job</a>}</span>
</h4>
</span>
<div class="description">
<p>Sets a job to repeat every X amount of time</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>interval</code></td>
<td class="type">
<span class="param-type">
String
</span>
</td>
<td class="description last">
<p>repeat every X</p>
</td>
</tr>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">
Object
</span>
</td>
<td class="description last">
<p>options to use for job</p>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="job_repeat-every.js.html">job/repeat-every.js</a>, <a href="job_repeat-every.js.html#line3">line 3</a>
</li>
</ul>
</dd>
</dl>
<span class='name-container'>
<a class="link-icon" href="#run">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="run">
<span class="type-signature"></span>run<span class="signature">()</span><span class="type-signature"> → {Promise}</span>
</h4>
</span>
<div class="description">
<p>Internal method (RUN)</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="job_run.js.html">job/run.js</a>, <a href="job_run.js.html#line4">line 4</a>
</li>
</ul>
</dd>
</dl>
<span class='name-container'>
<a class="link-icon" href="#schedule">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="schedule">
<span class="type-signature"></span>schedule<span class="signature">(time)</span><span class="type-signature"> → {exports}</span>
</h4>
</span>
<div class="description">
<p>Schedules a job to run at specified time</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>time</code></td>
<td class="type">
<span class="param-type">
String
</span>
</td>
<td class="description last">
<p>schedule a job to run "then"</p>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="job_schedule.js.html">job/schedule.js</a>, <a href="job_schedule.js.html#line4">line 4</a>
</li>
</ul>
</dd>
</dl>
<span class='name-container'>
<a class="link-icon" href="#toJSON">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="toJSON">
<span class="type-signature"></span>toJSON<span class="signature">()</span><span class="type-signature"> → {Object}</span>
</h4>
</span>
<div class="description">
<p>Given a job, turn it into an object we can store in Mongo</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="job_to-json.js.html">job/to-json.js</a>, <a href="job_to-json.js.html#line3">line 3</a>
</li>
</ul>
</dd>
</dl>
<span class='name-container'>
<a class="link-icon" href="#touch">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="touch">
<span class="type-signature"></span>touch<span class="signature">(cb)</span><span class="type-signature"> → {undefined}</span>
</h4>
</span>
<div class="description">
<p>Updates "lockedAt" time so the job does not get picked up again</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>cb</code></td>
<td class="type">
<span class="param-type">
function
</span>
</td>
<td class="description last">
<p>called when job "touch" fails or passes</p>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="job_touch.js.html">job/touch.js</a>, <a href="job_touch.js.html#line3">line 3</a>
</li>
</ul>
</dd>
</dl>
<span class='name-container'>
<a class="link-icon" href="#unique">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="unique">
<span class="type-signature"></span>unique<span class="signature">(unique, opts)</span><span class="type-signature"> → {exports}</span>
</h4>
</span>
<div class="description">
<p>Data to ensure is unique for job to be created</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>unique</code></td>
<td class="type">
<span class="param-type">
Object
</span>
</td>
<td class="description last">
<p>mongo data query for unique</p>
</td>
</tr>
<tr>
<td class="name"><code>opts</code></td>
<td class="type">
<span class="param-type">
Object
</span>
</td>
<td class="description last">
<p>unique options</p>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="job_unique.js.html">job/unique.js</a>, <a href="job_unique.js.html#line3">line 3</a>
</li>
</ul>
</dd>
</dl>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>
<script src="scripts/linenumber.js"></script>
<script src="scripts/pagelocation.js"></script>
</body>
</html>