MCPcopy Index your code
hub / github.com/node-schedule/node-schedule / prepareNextInvocation

Function prepareNextInvocation

lib/Invocation.js:239–294  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

237}
238
239function prepareNextInvocation() {
240 if (invocations.length > 0 && currentInvocation !== invocations[0]) {
241 if (currentInvocation !== null) {
242 lt.clearTimeout(currentInvocation.timerID);
243 currentInvocation.timerID = null;
244 currentInvocation = null;
245 }
246
247 currentInvocation = invocations[0];
248
249 const job = currentInvocation.job;
250 const cinv = currentInvocation;
251 currentInvocation.timerID = runOnDate(currentInvocation.fireDate, function() {
252 currentInvocationFinished();
253
254 if (job.callback) {
255 job.callback();
256 }
257
258 if (cinv.recurrenceRule.recurs || cinv.recurrenceRule._endDate === null) {
259 const inv = scheduleNextRecurrence(cinv.recurrenceRule, cinv.job, cinv.fireDate, cinv.endDate);
260 if (inv !== null) {
261 inv.job.trackInvocation(inv);
262 }
263 }
264
265 job.stopTrackingInvocation(cinv);
266
267 try {
268 const result = job.invoke(cinv.fireDate instanceof CronDate ? cinv.fireDate.toDate() : cinv.fireDate);
269 job.emit('run');
270 job.running += 1;
271
272 if (result instanceof Promise) {
273 result.then(function (value) {
274 job.emit('success', value);
275 job.running -= 1;
276 }).catch(function (err) {
277 job.emit('error', err);
278 job.running -= 1;
279 });
280 } else {
281 job.emit('success', result);
282 job.running -= 1;
283 }
284 } catch (err) {
285 job.emit('error', err);
286 job.running -= 1;
287 }
288
289 if (job.isOneTimeJob) {
290 job.deleteFromSchedule();
291 }
292 });
293 }
294}
295
296function currentInvocationFinished() {

Callers 3

scheduleInvocationFunction · 0.85
cancelInvocationFunction · 0.85

Calls 3

runOnDateFunction · 0.85
scheduleNextRecurrenceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…