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

Function Job

lib/Job.js:24–165  ·  view source on GitHub ↗
(name, job, callback)

Source from the content-addressed store, hash-verified

22}
23
24function Job(name, job, callback) {
25 // setup a private pendingInvocations variable
26 this.pendingInvocations = [];
27
28 //setup a private number of invocations variable
29 let triggeredJobs = 0;
30
31 // Set scope vars
32 const jobName = name && typeof name === 'string' ? name : resolveAnonJobName();
33 this.job = name && typeof name === 'function' ? name : job;
34
35 // Make sure callback is actually a callback
36 if (this.job === name) {
37 // Name wasn't provided and maybe a callback is there
38 this.callback = typeof job === 'function' ? job : false;
39 } else {
40 // Name was provided, and maybe a callback is there
41 this.callback = typeof callback === 'function' ? callback : false;
42 }
43
44 // task count
45 this.running = 0;
46
47 // Check for generator
48 if (typeof this.job === 'function' &&
49 this.job.prototype &&
50 this.job.prototype.next) {
51 this.job = function() {
52 return this.next().value;
53 }.bind(this.job.call(this));
54 }
55
56 // define properties
57 Object.defineProperty(this, 'name', {
58 value: jobName,
59 writable: false,
60 enumerable: true
61 });
62
63 // method that require private access
64 this.trackInvocation = function(invocation) {
65 // add to our invocation list
66 sorted.add(this.pendingInvocations, invocation, sorter);
67 return true;
68 };
69 this.stopTrackingInvocation = function(invocation) {
70 const invIdx = this.pendingInvocations.indexOf(invocation);
71 if (invIdx > -1) {
72 this.pendingInvocations.splice(invIdx, 1);
73 return true;
74 }
75
76 return false;
77 };
78 this.triggeredJobs = function() {
79 return triggeredJobs;
80 };
81 this.setTriggeredJobs = function(triggeredJob) {

Callers

nothing calls this directly

Calls 4

resolveAnonJobNameFunction · 0.85
deleteScheduledJobFunction · 0.85
cancelInvocationFunction · 0.85
scheduleNextRecurrenceFunction · 0.85

Tested by

no test coverage detected