Comparing version 1.6.0 to 1.7.0
@@ -0,1 +1,7 @@ | ||
## [1.7.0](https://github.com/bee-queue/bee-queue/compare/v1.6.0...v1.7.0) (2023-11-06) | ||
### Features | ||
- improve job failure events ([#227](https://github.com/bee-queue/bee-queue/issues/227)) ([15d02c2](https://github.com/bee-queue/bee-queue/commit/15d02c2f7e99505a4a7ce94c12d7311795d28c47)) | ||
## [1.6.0](https://github.com/bee-queue/bee-queue/compare/v1.5.0...v1.6.0) (2023-11-02) | ||
@@ -2,0 +8,0 @@ |
@@ -225,4 +225,21 @@ 'use strict'; | ||
} | ||
/** | ||
* Compute the delay for rescheduling the job after it fails. | ||
* | ||
* @return {number} The number of milliseconds into the future to schedule it. | ||
* Negative if no defined strategy or no remaining retries. | ||
*/ | ||
computeDelay() { | ||
const strategyName = this.options.backoff | ||
? this.options.backoff.strategy | ||
: 'immediate'; | ||
const strategy = | ||
this.options.retries > 0 | ||
? this.queue.backoffStrategies.get(strategyName) | ||
: null; | ||
return strategy ? strategy(this) : -1; | ||
} | ||
} | ||
module.exports = Job; |
@@ -594,5 +594,4 @@ 'use strict'; | ||
_finishJob(err, data, job) { | ||
const status = err ? 'failed' : 'succeeded'; | ||
if (this._isClosed) { | ||
const status = err ? 'failed' : 'succeeded'; | ||
throw new Error(`unable to update the status of ${status} job ${job.id}`); | ||
@@ -606,22 +605,13 @@ } | ||
const jobEvent = { | ||
id: job.id, | ||
event: status, | ||
data: err ? err.message : data, | ||
}; | ||
const delay = err ? job.computeDelay() : -1; | ||
const status = err ? (delay >= 0 ? 'retrying' : 'failed') : 'succeeded'; | ||
job.status = status; | ||
if (err) { | ||
const errInfo = err.stack || err.message || err; | ||
job.options.stacktraces.unshift(errInfo); | ||
} | ||
const strategyName = job.options.backoff | ||
? job.options.backoff.strategy | ||
: 'immediate'; | ||
const strategy = | ||
job.options.retries > 0 | ||
? this.backoffStrategies.get(strategyName) | ||
: null; | ||
const delay = strategy ? strategy(job) : -1; | ||
if (delay < 0) { | ||
job.status = 'failed'; | ||
switch (status) { | ||
case 'failed': | ||
if (this.settings.removeOnFailure) { | ||
@@ -633,6 +623,5 @@ multi.hdel(this.toKey('jobs'), job.id); | ||
} | ||
} else { | ||
job.options.retries -= 1; | ||
job.status = 'retrying'; | ||
jobEvent.event = 'retrying'; | ||
break; | ||
case 'retrying': | ||
--job.options.retries; | ||
multi.hset(this.toKey('jobs'), job.id, job.toData()); | ||
@@ -647,15 +636,22 @@ if (delay === 0) { | ||
} | ||
} | ||
} else { | ||
job.status = 'succeeded'; | ||
if (this.settings.removeOnSuccess) { | ||
multi.hdel(this.toKey('jobs'), job.id); | ||
} else { | ||
multi.hset(this.toKey('jobs'), job.id, job.toData()); | ||
multi.sadd(this.toKey('succeeded'), job.id); | ||
} | ||
break; | ||
case 'succeeded': | ||
if (this.settings.removeOnSuccess) { | ||
multi.hdel(this.toKey('jobs'), job.id); | ||
} else { | ||
multi.hset(this.toKey('jobs'), job.id, job.toData()); | ||
multi.sadd(this.toKey('succeeded'), job.id); | ||
} | ||
break; | ||
} | ||
if (this.settings.sendEvents) { | ||
multi.publish(this.toKey('events'), JSON.stringify(jobEvent)); | ||
multi.publish( | ||
this.toKey('events'), | ||
JSON.stringify({ | ||
id: job.id, | ||
event: status, | ||
data: err ? err.message : data, | ||
}) | ||
); | ||
} | ||
@@ -740,2 +736,13 @@ | ||
this.emit(status, job, result); | ||
// Workaround for #184: emit failed event for backwards | ||
// compatibility while affording for a separate event that | ||
// identifies the final failure. | ||
const emitExtra = | ||
status === 'retrying' | ||
? 'failed' | ||
: status === 'failed' | ||
? 'failed:fatal' | ||
: null; | ||
if (emitExtra) this.emit(emitExtra, job, result); | ||
} | ||
@@ -742,0 +749,0 @@ }, this._emitErrorAfterTick); |
{ | ||
"name": "bee-queue", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"description": "A simple, fast, robust job/task queue, backed by Redis.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
106156
1434