bree-plugin-one-time 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +14 -10
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -137,16 +137,20 @@ module.exports = function oneTimePlugin(options, Bree) {
137
137
 
138
138
  const originalStart = Bree.prototype.start;
139
139
 
140
- Bree.prototype.start = async function () {
141
- // `worker deleted` fires when a worker thread finishes (success or error)
142
- this.on('worker deleted', (name) => {
143
- const queue = loadQueue();
144
- const wasOneTime = queue.some(j => j.name === name);
145
- if (wasOneTime) {
146
- removeFromQueue(name);
147
- }
148
- });
140
+ Bree.prototype.start = async function (name) {
141
+ // Bree calls this.start(job.name) internally for each job only attach
142
+ // the cleanup listener on the initial no-arg "start everything" call to
143
+ // avoid infinite recursion (Bree binds this.start in the constructor).
144
+ if (!name) {
145
+ this.on('worker deleted', (workerName) => {
146
+ const queue = loadQueue();
147
+ const wasOneTime = queue.some(j => j.name === workerName);
148
+ if (wasOneTime) {
149
+ removeFromQueue(workerName);
150
+ }
151
+ });
152
+ }
149
153
 
150
- return originalStart.call(this);
154
+ return originalStart.call(this, name);
151
155
  };
152
156
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bree-plugin-one-time",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Persistent one-time job scheduling for Bree — jobs with a date property survive scheduler restarts",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",