@yellowpanther/shared 1.3.1 → 1.3.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yellowpanther/shared",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -33,6 +33,7 @@
33
33
  "./queue/quizPublishQueue": "./src/queue/quizPublishQueue.js",
34
34
  "./queue/predictPublishQueue": "./src/queue/predictPublishQueue.js",
35
35
  "./queue/queueRegistry": "./src/queue/queueRegistry.js",
36
+ "./queue/addUserPointsQueue": "./src/queue/addUserPointsQueue.js",
36
37
  "./lang/translationHelper": "./src/lang/translationHelper.js",
37
38
  "./*": "./src/*"
38
39
  },
package/src/index.js CHANGED
@@ -31,4 +31,5 @@ module.exports = {
31
31
  .addImageAlbumPublishJob,
32
32
  addEventPublishJob: require("./queue/eventPublishQueue").addEventPublishJob,
33
33
  addShopPublishJob: require("./queue/shopPublishQueue").addShopPublishJob,
34
+ addUserPointsJob: require("./queue/addUserPointsQueue").addUserPointsJob,
34
35
  };
@@ -0,0 +1,49 @@
1
+
2
+ const { Queue } = require("bullmq");
3
+ const redisClient = require("../redis/redisClient");
4
+
5
+ const DEBUG = String(process.env.DEBUG_LOGGER || "").trim() === "1";
6
+
7
+ const addUserPointsQueue = new Queue("addUserPointsQueue", {
8
+ connection: redisClient,
9
+ defaultJobOptions: {
10
+ attempts: 5,
11
+ backoff: { type: "exponential", delay: 2000 },
12
+ removeOnComplete: 500,
13
+ removeOnFail: 500,
14
+ },
15
+ });
16
+
17
+ function sanitizeId(str) {
18
+ return str.replace(/[:.]/g, "-");
19
+ }
20
+
21
+ function stableJobId(option_id) {
22
+ return sanitizeId(`addUserPointsQueue:${option_id}`);
23
+ }
24
+
25
+ function versionedJobId(option_id) {
26
+ return sanitizeId(`addUserPoints:${option_id}`);
27
+ }
28
+
29
+ async function addUserPointsJob(correctOption, useStableId = false){
30
+ // const jobId = useStableId
31
+ // ? stableJobId(correctOption.id)
32
+ // : versionedJobId(correctOption.id);
33
+
34
+ const job = await addUserPointsQueue.add(
35
+ "addUserPointsQueue",
36
+ { option_id: correctOption.id },
37
+ // { jobId }
38
+ );
39
+
40
+ if (DEBUG) {
41
+ console.info("[addUserPointsQueue] upsert", {
42
+ option_id: correctOption.id,
43
+ // jobId,
44
+ });
45
+ }
46
+ return job;
47
+ }
48
+
49
+ module.exports = {addUserPointsJob}