clever-queue 0.2.4 → 0.3.0

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/.gitlab-ci.yml CHANGED
@@ -25,26 +25,37 @@ variables:
25
25
  NPM_TOKEN: ${CI_JOB_TOKEN}
26
26
 
27
27
  stages:
28
- - build
29
28
  - test
29
+ - install
30
+ - build
31
+ - unit_test
30
32
  - release
31
33
  - publish
32
34
 
35
+ install:
36
+ image: node:24
37
+ stage: install
38
+ script:
39
+ - npm install
40
+ artifacts:
41
+ when: always
42
+ paths:
43
+ - node_modules/
44
+
33
45
  build:
34
46
  image: node:24
35
47
  stage: build
48
+ needs: [install]
36
49
  script:
37
- - npm install
38
50
  - npm run build
39
51
  artifacts:
40
52
  when: always
41
53
  paths:
42
- - node_modules/
43
54
  - dist/
44
55
 
45
- test:
56
+ unit_test:
46
57
  image: node:24
47
- stage: test
58
+ stage: unit_test
48
59
  needs: [build]
49
60
  script:
50
61
  - npm run test:junit
@@ -54,18 +65,19 @@ test:
54
65
  junit:
55
66
  - junit.xml
56
67
 
57
- semantic-release:
68
+ release:
58
69
  image: node:24
59
70
  stage: release
60
- needs: [build]
71
+ needs: [install, unit_test]
61
72
  script:
62
73
  - npm run semantic-release
63
74
  rules:
64
- - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
75
+ - if: $CI_COMMIT_BRANCH =~ /^v\d+\.\d+$/
65
76
 
66
77
  publish:
67
78
  image: node:24
68
79
  stage: publish
80
+ needs: [release]
69
81
  id_tokens:
70
82
  NPM_ID_TOKEN:
71
83
  aud: "npm:registry.npmjs.org"
@@ -1,6 +1,6 @@
1
1
  import * as _ from "../helpers";
2
2
  import * as Runner from "../runners/interfaces";
3
- import * as Queue from "../runners/interfaces";
3
+ import * as Queue from "../queues/interfaces";
4
4
  interface Options {
5
5
  id?: string;
6
6
  autostart?: boolean;
@@ -63,8 +63,8 @@ class Queue {
63
63
  throw new _.Errors.CQError(interfaces_1.ErrorsList.NoOptionsOnQueueInitialization);
64
64
  if (!(typeof options.priority === "number") || options.priority < 0 || options.priority > 255)
65
65
  throw new _.Errors.CQError(interfaces_1.ErrorsList.BadPriorityOptionsOnQueueInitialization, options);
66
- if (!options.weight)
67
- throw new _.Errors.CQError(interfaces_1.ErrorsList.NoWeightOptionsOnQueueInitialization);
66
+ if (!(typeof options.weight === "number") || options.weight < interfaces_1.Weights.Lowest || options.weight > interfaces_1.Weights.Highest)
67
+ throw new _.Errors.CQError(interfaces_1.ErrorsList.NoWeightOptionsOnQueueInitialization, options);
68
68
  return options;
69
69
  }
70
70
  start() {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/queues/index.ts"],"names":[],"mappings":";AAAA,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEf,8CAAgC;AAChC,iDAAmC;AACnC,6CAA2E;AAM3E,MAAM,cAAc,GAAY;IAC9B,SAAS,EAAE,IAAI;IACf,QAAQ,EAAE,uBAAU,CAAC,QAAQ;IAC7B,MAAM,EAAE,GAAG;IACX,WAAW,EAAE,SAAS;CACvB,CAAC;AAEF,MAAM,KAAK;IACT,MAAM,GAAW,SAAS,CAAC;IAClB,OAAO,CAAU;IAC1B,IAAI,GAAiD,EAAE,CAAC;IAExD,IAAI,GAAW,CAAC,CAAC;IACjB,KAAK,GAAkB,EAAE,CAAC;IAE1B,YAAY,GAAY;QACtB,IAAI,CAAC,MAAM,GAAG,eAAe,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,wBAAwB,CAAC,EAAE,GAAG,cAAc,EAAE,GAAG,GAAG,EAAE,CAAC,CAAC;QAC5E,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;YAAE,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC;QACxD,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS;YAAE,IA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IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,qDAAqD;QACrF,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;YACxB,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC;YACvB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,UAAU;QACR,MAAM,IAAI,GAAe;YACvB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;YAC/B,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;YAC3B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM;SACzB,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAGQ,sBAAK;AADd,2CAAoF;AAAtD,wGAAA,UAAU,OAAA;AAAE,wGAAA,UAAU,OAAA;AAAE,qGAAA,OAAO,OAAA"}
@@ -12,7 +12,7 @@ const ErrorsList = {
12
12
  },
13
13
  NoWeightOptionsOnQueueInitialization: {
14
14
  name: "NoWeightOptionsOnQueueInitialization",
15
- message: "You must provide a 'weight' parameter for Queue initialization",
15
+ message: "You must provide a 'weight' parameter for Queue initialization from 0 to 255, you may use CleverQueue.Weights constants",
16
16
  },
17
17
  NoOptionsOnQueueInitialization: { name: "NoOptionsOnQueueInitialization", message: "You must provide an options parameter to Queue" },
18
18
  };
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/queues/interfaces.ts"],"names":[],"mappings":";;;AAEA,MAAM,UAAU,GAAG,EAAE,UAAU,EAAE,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAG,QAAQ,EAAE,GAAG,EAAC,CAAC;AAoCzB,gCAAU;AAnCpD,MAAM,OAAO,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;AAmCJ,0BAAO;AAhB7D,MAAM,UAAU,GAEZ;IACF,uCAAuC,EAAE;QACvC,IAAI,EAAE,yCAAyC;QAC/C,OAAO,EACL,yKAAyK;KAC5K;IACD,oCAAoC,EAAE;QACpC,IAAI,EAAE,sCAAsC;QAC5C,OAAO,EAAE,gEAAgE;KAC1E;IAED,8BAA8B,EAAE,EAAE,IAAI,EAAE,gCAAgC,EAAE,OAAO,EAAE,gDAAgD,EAAE;CACtI,CAAC;AAE4B,gCAAU"}
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/queues/interfaces.ts"],"names":[],"mappings":";;;AAEA,MAAM,UAAU,GAAG,EAAE,UAAU,EAAE,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;AAoCzB,gCAAU;AAnCpD,MAAM,OAAO,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;AAmCJ,0BAAO;AAhB7D,MAAM,UAAU,GAEZ;IACF,uCAAuC,EAAE;QACvC,IAAI,EAAE,yCAAyC;QAC/C,OAAO,EACL,yKAAyK;KAC5K;IACD,oCAAoC,EAAE;QACpC,IAAI,EAAE,sCAAsC;QAC5C,OAAO,EAAE,yHAAyH;KACnI;IAED,8BAA8B,EAAE,EAAE,IAAI,EAAE,gCAAgC,EAAE,OAAO,EAAE,gDAAgD,EAAE;CACtI,CAAC;AAE4B,gCAAU"}
@@ -78,7 +78,12 @@ class Task {
78
78
  }
79
79
  catch (error) {
80
80
  this.status = "exception";
81
- this.rejecter(new _.Errors.CQError(interfaces_1.ErrorsList.FunctionRaisedAnHundledException));
81
+ if (error instanceof Error) {
82
+ this.rejecter(error);
83
+ }
84
+ else {
85
+ this.rejecter(new _.Errors.CQError(interfaces_1.ErrorsList.FunctionRaisedAnHundledException));
86
+ }
82
87
  }
83
88
  };
84
89
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tasks/index.ts"],"names":[],"mappings":";AAAA,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEf,8CAAgC;AAChC,6CAAkF;AAIlF,MAAM,cAAc,GAAY;IAC9B,WAAW,EAAE,SAAS;CACvB,CAAC;AAEF,MAAM,IAAI;IACR,MAAM,GAAW,SAAS,CAAC;IAClB,OAAO,CAAU;IAC1B,IAAI,GAAiD,EAAE,CAAC;IACxD,OAAO,CAAqB;IAC5B,QAAQ,CAAqB;IAE7B,kBAAkB,CAAoB;IACtC,MAAM,GAAwB,SAAS,CAAC;IAC/B,GAAG,CAAyB;IAErC,8DAA8D;IAC9D,QAAQ,CAA0C;IAClD,8DAA8D;IAC9D,QAAQ,CAAyB;IAEjC,gBAAgB;QACd,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,uBAAU,CAAC,wBAAwB,CAAC,CAAC;IAClE,CAAC;IACD,gBAAgB;QACd,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,uBAAU,CAAC,wBAAwB,CAAC,CAAC;IAClE,CAAC;IAED,YAAY,SAA4B,EAAE,GAAY;QACpD,IAAI,CAAC,MAAM,GAAG,eAAe,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,wBAAwB,CAAC,EAAE,GAAG,cAAc,EAAE,GAAG,GAAG,EAAE,CAAC,CAAC;QAC5E,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;YAAE,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC;QACxD,IAAI,OAAO,SAAS,KAAK,UAAU;YAAE,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,uBAAU,CAAC,sBAAsB,CAAC,C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C;YACxB,IAAI,CAAC;gBACH,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBAC9C,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC;gBACvB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC7B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC;gBAC1B,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;oBAC3B,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;gBACvB,CAAC;qBAAM,CAAC;oBACN,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,uBAAU,CAAC,gCAAgC,CAAC,CAAC,CAAC;gBACnF,CAAC;YACH,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;IAED,wBAAwB,CAAC,OAAgB;QACvC,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,uBAAU,CAAC,6BAA6B,CAAC,CAAC;QACnF,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,UAAU;QACR,MAAM,IAAI,GAAe;YACvB,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAGQ,oBAAI;AADb,2CAAkF;AAApD,wGAAA,UAAU,OAAA"}
package/eslint.config.mjs CHANGED
@@ -47,6 +47,7 @@ export default [
47
47
 
48
48
  "@typescript-eslint/no-explicit-any": "warn",
49
49
  "@typescript-eslint/explicit-function-return-type": "warn",
50
+ "unicorn/expiring-todo-comments": "off",
50
51
  "unicorn/filename-case": "off",
51
52
  "unicorn/prevent-abbreviations": "warn",
52
53
  "security/detect-object-injection": "off",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clever-queue",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "description": "Queuing system for promises that handle concurring, throttling, weighting and prioritizing in a clever fashion.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -10,6 +10,7 @@
10
10
  "prestart": "npx npm run build",
11
11
  "start": "node dist/index.js",
12
12
  "debug": "node --nolazy --inspect-brk=9229 dist/index.js",
13
+ "pretest": "npm run build",
13
14
  "test": "node --test ./test/**/*.mjs",
14
15
  "test:junit": "node --test --test-reporter=junit --test-reporter-destination=junit.xml ./test/**/*.mjs",
15
16
  "test:unit:watch": "node --test --watch ./test/units/*.mjs",
@@ -21,7 +22,15 @@
21
22
  },
22
23
  "release": {
23
24
  "branches": [
24
- "v0"
25
+ "v+([0-9]).+([0-9])"
26
+ ],
27
+ "plugins": [
28
+ [
29
+ "@semantic-release/gitlab",
30
+ {
31
+ "useJobToken": true
32
+ }
33
+ ]
25
34
  ]
26
35
  },
27
36
  "keywords": [
@@ -46,6 +55,7 @@
46
55
  "@opentelemetry/sdk-metrics": "^1.26",
47
56
  "@opentelemetry/sdk-node": "^0.53",
48
57
  "@opentelemetry/sdk-trace-node": "^1.26",
58
+ "@semantic-release/gitlab": "^13.3.2",
49
59
  "@types/eslint__js": "^8.42",
50
60
  "@types/node": "^22.1",
51
61
  "eslint": "^9.8",
@@ -58,8 +68,8 @@
58
68
  "fast-xml-parser": "^5.0.9",
59
69
  "globals": "^15.9",
60
70
  "node": "^24.12",
61
- "semantic-release": "^25.0.2",
71
+ "semantic-release": "^25.0.3",
62
72
  "typescript": "^5.9",
63
73
  "typescript-eslint": "^8.50"
64
74
  }
65
- }
75
+ }
@@ -1,7 +1,7 @@
1
1
  import * as _ from "../helpers";
2
2
 
3
3
  import * as Runner from "../runners/interfaces";
4
- import * as Queue from "../runners/interfaces";
4
+ import * as Queue from "../queues/interfaces";
5
5
 
6
6
  interface Options {
7
7
  id?: string;
@@ -2,7 +2,7 @@
2
2
 
3
3
  import * as _ from "../helpers";
4
4
  import * as cqTask from "../tasks";
5
- import { Options, Statistics, ErrorsList, Priorities } from "./interfaces";
5
+ import { Options, Statistics, ErrorsList, Priorities, Weights } from "./interfaces";
6
6
 
7
7
  type GetSumWeightFunction = (priority: number) => number;
8
8
 
@@ -34,7 +34,8 @@ class Queue {
34
34
  if (!options) throw new _.Errors.CQError(ErrorsList.NoOptionsOnQueueInitialization);
35
35
  if (!(typeof options.priority === "number") || options.priority < 0 || options.priority > 255)
36
36
  throw new _.Errors.CQError(ErrorsList.BadPriorityOptionsOnQueueInitialization, options);
37
- if (!options.weight) throw new _.Errors.CQError(ErrorsList.NoWeightOptionsOnQueueInitialization);
37
+ if (!(typeof options.weight === "number") || options.weight < Weights.Lowest || options.weight > Weights.Highest)
38
+ throw new _.Errors.CQError(ErrorsList.NoWeightOptionsOnQueueInitialization, options);
38
39
  return options;
39
40
  }
40
41
 
@@ -1,6 +1,6 @@
1
1
  import * as _ from "../helpers";
2
2
 
3
- const Priorities = { BestEffort: 0, Standard: 128, Absolute: 255};
3
+ const Priorities = { BestEffort: 0, Standard: 128, Absolute: 255 };
4
4
  const Weights = { Lowest: 0, Default: 128, Highest: 255 };
5
5
 
6
6
  interface Options {
@@ -30,7 +30,7 @@ const ErrorsList: {
30
30
  },
31
31
  NoWeightOptionsOnQueueInitialization: {
32
32
  name: "NoWeightOptionsOnQueueInitialization",
33
- message: "You must provide a 'weight' parameter for Queue initialization",
33
+ message: "You must provide a 'weight' parameter for Queue initialization from 0 to 255, you may use CleverQueue.Weights constants",
34
34
  },
35
35
 
36
36
  NoOptionsOnQueueInitialization: { name: "NoOptionsOnQueueInitialization", message: "You must provide an options parameter to Queue" },
@@ -50,7 +50,11 @@ class Task {
50
50
  this.resolver(this.result);
51
51
  } catch (error) {
52
52
  this.status = "exception";
53
- this.rejecter(new _.Errors.CQError(ErrorsList.FunctionRaisedAnHundledException));
53
+ if (error instanceof Error) {
54
+ this.rejecter(error);
55
+ } else {
56
+ this.rejecter(new _.Errors.CQError(ErrorsList.FunctionRaisedAnHundledException));
57
+ }
54
58
  }
55
59
  };
56
60
  }
@@ -8,28 +8,30 @@ const engineOptions = {
8
8
  logFunction: undefined,
9
9
  };
10
10
 
11
- const task = async (string_) => {
12
- // console.log(string_, "Start", new Date());
13
- await new Promise((resolve, reject) => setTimeout(reject(string_), 2000));
14
- // console.log(string_, "End", new Date());
15
- return string_;
11
+
12
+ const task = async (customErrorMessage) => {
13
+ await new Promise((resolve) => setTimeout(resolve, 1000));
14
+ throw customErrorMessage; // this is the not tight way to throw an exception, but it is to test the case where the function raises an exception that is not an instance of Error
16
15
  };
17
16
 
18
17
  describe("Issue #1", () => {
19
- it("Exception if function passed raised an exception", () => {
18
+ it("Exception if function passed raised an exception that is not an instance of Error", async () => {
20
19
  const engine = cleverQueue.createEngine(engineOptions);
21
20
  const queue1 = engine.createQueue({
22
21
  name: "A",
23
22
  priority: cleverQueue.queues.Priorities.Absolute,
24
23
  weight: 50,
25
24
  });
26
- assert.rejects(
27
- async () => {
28
- const myTask = engine.createTask(() => task("taskMustFail"), {});
29
- await queue1.enqueue(myTask);
30
- },
31
- { name: "FunctionRaisedAnHundledException" },
32
- );
33
- engine.stop();
25
+ try {
26
+ await assert.rejects(
27
+ async () => {
28
+ const myTask = engine.createTask(() => task("a message exception that is not an instance of Error"), {});
29
+ await queue1.enqueue(myTask);
30
+ },
31
+ { name: cleverQueue.tasks.ErrorsList.FunctionRaisedAnHundledException.name },
32
+ );
33
+ } finally {
34
+ engine.stop();
35
+ }
34
36
  });
35
37
  });
@@ -0,0 +1,38 @@
1
+ import assert from "node:assert/strict";
2
+ import { describe, it } from "node:test";
3
+
4
+ import * as cleverQueue from "../../dist/index.js";
5
+
6
+ const engineOptions = {
7
+ bestEffortRunners: 1,
8
+ logFunction: undefined,
9
+ };
10
+
11
+
12
+ const task = async (customErrorMessage) => {
13
+ await new Promise((resolve) => setTimeout(resolve, 1000));
14
+ if (customErrorMessage) throw new Error(customErrorMessage); // this is the not tight way to throw an exception, but it is to test the case where the function raises an exception that is not an instance of Error
15
+ };
16
+
17
+ describe("Issue #2", () => {
18
+ it("Exception if function passed raised an exception with a correct Error Object", async () => {
19
+ const engine = cleverQueue.createEngine(engineOptions);
20
+ const queue1 = engine.createQueue({
21
+ name: "A",
22
+ priority: cleverQueue.queues.Priorities.Absolute,
23
+ weight: 50,
24
+ });
25
+ const customErrorMessage = "Custom error message";
26
+ try {
27
+ await assert.rejects(
28
+ async () => {
29
+ const myTask = engine.createTask(() => task(customErrorMessage), {});
30
+ await queue1.enqueue(myTask);
31
+ },
32
+ { name: "Error", message: customErrorMessage },
33
+ );
34
+ } finally {
35
+ engine.stop();
36
+ }
37
+ });
38
+ });
@@ -31,4 +31,21 @@ describe("Queue Class Unit Tests", () => {
31
31
  assert.equal(queueStatistics.weight, queueOptions.weight);
32
32
  engine.stop();
33
33
  });
34
+
35
+ it("Rejects negative weight because queue weights must stay within the supported range", () => {
36
+ const engine = cleverQueue.createEngine(engineOptions);
37
+ assert.throws(
38
+ () =>
39
+ engine.createQueue({
40
+ priority: cleverQueue.queues.Priorities.Standard,
41
+ weight: -1,
42
+ }),
43
+ { name: cleverQueue.queues.ErrorsList.NoWeightOptionsOnQueueInitialization.name },
44
+ );
45
+ engine.stop();
46
+ });
47
+
48
+ it("Keeps the exported lowest weight constant at zero", () => {
49
+ assert.equal(cleverQueue.queues.Weights.Lowest, 0);
50
+ });
34
51
  });