MCPcopy
hub / github.com/bee-queue/bee-queue / _save

Method _save

lib/job.js:54–100  ·  view source on GitHub ↗
(evalScript)

Source from the content-addressed store, hash-verified

52 // For Queue#saveAll, this method is guaranteed to invoke evalScript
53 // synchronously.
54 _save(evalScript) {
55 const toKey = this.queue.toKey.bind(this.queue);
56
57 let promise;
58 if (this.options.delay) {
59 promise = evalScript([
60 'addDelayedJob',
61 4,
62 toKey('id'),
63 toKey('jobs'),
64 toKey('delayed'),
65 toKey('earlierDelayed'),
66 this.id || '',
67 this.toData(),
68 this.options.delay,
69 ]);
70
71 if (this.queue.settings.activateDelayedJobs) {
72 promise = promise.then((jobId) => {
73 // Only reschedule if the job was actually created.
74 if (jobId) {
75 this.queue._delayedTimer.schedule(this.options.delay);
76 }
77 return jobId;
78 });
79 }
80 } else {
81 promise = evalScript([
82 'addJob',
83 3,
84 toKey('id'),
85 toKey('jobs'),
86 toKey('waiting'),
87 this.id || '',
88 this.toData(),
89 ]);
90 }
91
92 return promise.then((jobId) => {
93 this.id = jobId;
94 // If the jobId is not null, then store the job in the job map.
95 if (jobId && this.queue.settings.storeJobs) {
96 this.queue.jobs.set(jobId, this);
97 }
98 return this;
99 });
100 }
101
102 save(cb) {
103 const promise = this._save((args) =>

Callers 2

saveMethod · 0.95
saveAllMethod · 0.80

Calls 2

toDataMethod · 0.95
scheduleMethod · 0.80

Tested by

no test coverage detected