playov2-js-utilities 0.3.36 → 0.3.38

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.
@@ -3,8 +3,18 @@ const Schema = mongoose.Schema;
3
3
 
4
4
  // compound index on queuId and taskId and status, so that a task is saved only once per queue
5
5
  const scheduledTaskSchema = new Schema({
6
+ httpMethod: {
7
+ type: String,
8
+ enum: ["GET", "POST", "PUT", "DELETE"],
9
+ default: "POST",
10
+ },
6
11
  taskId: { type: String, required: true },
7
12
  queueId: { type: String, required: true },
13
+ url: {
14
+ type: String,
15
+ required: true,
16
+ },
17
+ ttl: {},
8
18
  payload: {
9
19
 
10
20
  },
@@ -20,7 +30,7 @@ const scheduledTaskSchema = new Schema({
20
30
  type: String,
21
31
  enum: ['saved', 'executed', 'failed', 'cancelled'],
22
32
  default: 'saved',
23
- required: true
33
+ required: true
24
34
  },
25
35
  lastExecutionDetails: {
26
36
 
@@ -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
- this.message = message;
20
- this.name = name;
19
+ const error = new Error(message);
20
+ error.name = name;
21
+ return error;
21
22
  };
22
23
 
23
24
  /**
@@ -52,10 +53,15 @@ const saveFutureTask = async (queueId, taskId, payload, eta, count = MAX_RETRY_C
52
53
  await task.save();
53
54
 
54
55
  } catch (err) {
55
- if (err.message !== "RetryableException") {
56
+ const errMessage = err && err.message ? err.message : 'Exception';
57
+ // in case there's an exception which shouldn't be retried, such as improper parameter, this throws the error to be
58
+ // handled by the originating calling function
59
+ if (errMessage !== "RetryableException") {
56
60
  throw err;
57
61
  }
58
62
 
63
+ // This is a mechanism to handle unexpected network failure / disconnection to db.
64
+ // This seems lame though, probably should pair with set timeout for exponential back off.
59
65
  if (count === 0) {
60
66
  Logger.prepareAlertLog(requestId, { func: 'saveFutureTask', queueId, taskId, payload, eta, err }, 'saving future task failed!');
61
67
  throw err;
@@ -65,7 +71,6 @@ const saveFutureTask = async (queueId, taskId, payload, eta, count = MAX_RETRY_C
65
71
  }
66
72
  };
67
73
 
68
-
69
74
  const deleteScheduledTask = async (queueId, taskId, count = MAX_RETRY_COUNT, requestId) => {
70
75
  try {
71
76
  if (!queueId || !taskId) {
@@ -92,6 +97,5 @@ const deleteScheduledTask = async (queueId, taskId, count = MAX_RETRY_COUNT, req
92
97
 
93
98
  module.exports = {
94
99
  saveFutureTask,
95
- // pushScheduledTaskToQueue,
96
100
  deleteScheduledTask
97
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playov2-js-utilities",
3
- "version": "0.3.36",
3
+ "version": "0.3.38",
4
4
  "description": "Private package for JS utility functions",
5
5
  "main": "index.js",
6
6
  "scripts": {