mirror of
https://github.com/OptimalBits/bull.git
synced 2026-07-02 08:27:43 +08:00
fix(job): check jobKey when saving stacktrace (#2755)
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
--[[
|
||||
Save stacktrace and failedReason.
|
||||
|
||||
Input:
|
||||
KEYS[1] job key
|
||||
|
||||
ARGV[1] stacktrace
|
||||
ARGV[2] failedReason
|
||||
ARGV[3] attemptsMade
|
||||
|
||||
Output:
|
||||
0 - OK
|
||||
-1 - Missing key
|
||||
]]
|
||||
local rcall = redis.call
|
||||
|
||||
if rcall("EXISTS", KEYS[1]) == 1 then
|
||||
rcall("HMSET", KEYS[1], "stacktrace", ARGV[1], "failedReason", ARGV[2],
|
||||
"attemptsMade", ARGV[3])
|
||||
|
||||
return 0
|
||||
else
|
||||
return -1
|
||||
end
|
||||
+12
-9
@@ -582,19 +582,22 @@ Job.prototype._isInList = function(list) {
|
||||
Job.prototype._saveAttempt = function(multi, err) {
|
||||
this.attemptsMade++;
|
||||
|
||||
const params = {
|
||||
attemptsMade: this.attemptsMade
|
||||
};
|
||||
this.stacktrace = this.stacktrace || [];
|
||||
|
||||
if (this.opts.stackTraceLimit) {
|
||||
this.stacktrace = this.stacktrace.slice(0, this.opts.stackTraceLimit - 1);
|
||||
if (err && err.stack) {
|
||||
this.stacktrace.push(err.stack);
|
||||
if (this.opts.stackTraceLimit) {
|
||||
this.stacktrace = this.stacktrace.slice(-this.opts.stackTraceLimit);
|
||||
}
|
||||
}
|
||||
|
||||
this.stacktrace.push(err.stack);
|
||||
params.stacktrace = JSON.stringify(this.stacktrace);
|
||||
params.failedReason = err.message;
|
||||
const args = scripts.saveStacktraceArgs(
|
||||
this,
|
||||
JSON.stringify(this.stacktrace),
|
||||
err && err.message,
|
||||
);
|
||||
|
||||
multi.hmset(this.queue.toKey(this.id), params);
|
||||
multi.saveStacktrace(args);
|
||||
};
|
||||
|
||||
Job.fromJSON = function(queue, json, jobId) {
|
||||
|
||||
@@ -163,6 +163,18 @@ const scripts = {
|
||||
return queue.client.updateData(keys, [dataJson]);
|
||||
},
|
||||
|
||||
saveStacktraceArgs(
|
||||
job,
|
||||
stacktrace,
|
||||
failedReason
|
||||
) {
|
||||
const queue = job.queue;
|
||||
|
||||
const keys = [queue.toKey(job.id)];
|
||||
|
||||
return keys.concat([stacktrace, failedReason, job.attemptsMade]);
|
||||
},
|
||||
|
||||
retryJobsArgs(queue, count) {
|
||||
const keys = [
|
||||
queue.toKey(''),
|
||||
|
||||
Reference in New Issue
Block a user