playov2-js-utilities 0.3.37 → 0.3.39
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.
- package/lib/taskscheduler/index.js +12 -5
- package/package.json +1 -1
|
@@ -16,8 +16,9 @@ const MAX_RETRY_COUNT = 5;
|
|
|
16
16
|
* @param {String} name - Optional - If "RetryableException", then function will be retried till MAX_RETRY_COUNT
|
|
17
17
|
*/
|
|
18
18
|
function CTException(message, name) {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const error = new Error(message);
|
|
20
|
+
error.name = name;
|
|
21
|
+
return error;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
/**
|
|
@@ -38,8 +39,11 @@ const saveFutureTask = async (queueId, taskId, payload, eta, count = MAX_RETRY_C
|
|
|
38
39
|
throw CTException('eta can not be before 30 days from now. Schedule directly!', 'ValidationException')
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
const { url, httpMethod } = payload;
|
|
41
43
|
const taskData = {
|
|
42
44
|
taskId,
|
|
45
|
+
url,
|
|
46
|
+
httpMethod,
|
|
43
47
|
payload,
|
|
44
48
|
queueId,
|
|
45
49
|
activationTime: eta,
|
|
@@ -52,10 +56,15 @@ const saveFutureTask = async (queueId, taskId, payload, eta, count = MAX_RETRY_C
|
|
|
52
56
|
await task.save();
|
|
53
57
|
|
|
54
58
|
} catch (err) {
|
|
55
|
-
|
|
59
|
+
const errMessage = err && err.message ? err.message : 'Exception';
|
|
60
|
+
// in case there's an exception which shouldn't be retried, such as improper parameter, this throws the error to be
|
|
61
|
+
// handled by the originating calling function
|
|
62
|
+
if (errMessage !== "RetryableException") {
|
|
56
63
|
throw err;
|
|
57
64
|
}
|
|
58
65
|
|
|
66
|
+
// This is a mechanism to handle unexpected network failure / disconnection to db.
|
|
67
|
+
// This seems lame though, probably should pair with set timeout for exponential back off.
|
|
59
68
|
if (count === 0) {
|
|
60
69
|
Logger.prepareAlertLog(requestId, { func: 'saveFutureTask', queueId, taskId, payload, eta, err }, 'saving future task failed!');
|
|
61
70
|
throw err;
|
|
@@ -65,7 +74,6 @@ const saveFutureTask = async (queueId, taskId, payload, eta, count = MAX_RETRY_C
|
|
|
65
74
|
}
|
|
66
75
|
};
|
|
67
76
|
|
|
68
|
-
|
|
69
77
|
const deleteScheduledTask = async (queueId, taskId, count = MAX_RETRY_COUNT, requestId) => {
|
|
70
78
|
try {
|
|
71
79
|
if (!queueId || !taskId) {
|
|
@@ -92,6 +100,5 @@ const deleteScheduledTask = async (queueId, taskId, count = MAX_RETRY_COUNT, req
|
|
|
92
100
|
|
|
93
101
|
module.exports = {
|
|
94
102
|
saveFutureTask,
|
|
95
|
-
// pushScheduledTaskToQueue,
|
|
96
103
|
deleteScheduledTask
|
|
97
104
|
}
|