clever-queue 0.1.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 +13 -0
- package/.prettierrc.json +4 -0
- package/README.md +15 -0
- package/dist/engine/index.d.ts +21 -0
- package/dist/engine/index.js +187 -0
- package/dist/engine/index.js.map +1 -0
- package/dist/engine/interfaces.d.ts +28 -0
- package/dist/engine/interfaces.js +9 -0
- package/dist/engine/interfaces.js.map +1 -0
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +42 -0
- package/dist/errors.js.map +1 -0
- package/dist/helpers/errors.d.ts +7 -0
- package/dist/helpers/errors.js +20 -0
- package/dist/helpers/errors.js.map +1 -0
- package/dist/helpers/index.d.ts +3 -0
- package/dist/helpers/index.js +30 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/logs.d.ts +75 -0
- package/dist/helpers/logs.js +32 -0
- package/dist/helpers/logs.js.map +1 -0
- package/dist/helpers/traces.d.ts +1 -0
- package/dist/helpers/traces.js +24 -0
- package/dist/helpers/traces.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/queue/index.d.ts +19 -0
- package/dist/queue/index.js +110 -0
- package/dist/queue/index.js.map +1 -0
- package/dist/queue/interfaces.d.ts +27 -0
- package/dist/queue/interfaces.js +18 -0
- package/dist/queue/interfaces.js.map +1 -0
- package/dist/runner/index.d.ts +14 -0
- package/dist/runner/index.js +83 -0
- package/dist/runner/index.js.map +1 -0
- package/dist/runner/interfaces.d.ts +19 -0
- package/dist/runner/interfaces.js +13 -0
- package/dist/runner/interfaces.js.map +1 -0
- package/dist/task/index.d.ts +14 -0
- package/dist/task/index.js +81 -0
- package/dist/task/index.js.map +1 -0
- package/dist/task/interfaces.d.ts +17 -0
- package/dist/task/interfaces.js +19 -0
- package/dist/task/interfaces.js.map +1 -0
- package/eslint.config.mjs +68 -0
- package/exemples/index01.js +116 -0
- package/exemples/index01.ts +98 -0
- package/exemples/index02.mjs +13 -0
- package/exemples/tsconfig.json +24 -0
- package/package.json +55 -0
- package/src/engine/index.ts +166 -0
- package/src/engine/interfaces.ts +33 -0
- package/src/helpers/errors.ts +16 -0
- package/src/helpers/index.ts +3 -0
- package/src/helpers/logs.ts +91 -0
- package/src/helpers/traces.ts +24 -0
- package/src/index.ts +13 -0
- package/src/queue/index.ts +93 -0
- package/src/queue/interfaces.ts +38 -0
- package/src/runner/index.ts +64 -0
- package/src/runner/interfaces.ts +24 -0
- package/src/task/index.ts +65 -0
- package/src/task/interfaces.ts +34 -0
- package/src/tsconfig.json +27 -0
- package/test/miscellaneous/test.mjs +92 -0
- package/test/units/engine.mjs +35 -0
- package/test/units/queue.mjs +34 -0
- package/test/units/task.mjs +50 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// clever-queue
|
|
2
|
+
|
|
3
|
+
import * as _ from "../helpers";
|
|
4
|
+
import { Options, Statistics, ErrorsList, Priorities } from "./interfaces";
|
|
5
|
+
import { Engine } from "../engine";
|
|
6
|
+
|
|
7
|
+
export * from "./interfaces";
|
|
8
|
+
|
|
9
|
+
type Status = "unknown" | "initialiazing" | "running" | "stopping" | "destroying";
|
|
10
|
+
|
|
11
|
+
const defaultOptions: Options = {
|
|
12
|
+
priority: Priorities.BestEffort,
|
|
13
|
+
autostart: true,
|
|
14
|
+
logFunction: undefined,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
class Runner {
|
|
18
|
+
status: Status = "unknown";
|
|
19
|
+
readonly #options: Options;
|
|
20
|
+
readonly #engine: Engine;
|
|
21
|
+
|
|
22
|
+
constructor(opt: Options, engine: Engine) {
|
|
23
|
+
this.status = "initialiazing";
|
|
24
|
+
this.#options = this.#checkOptionsConsistancy({ ...defaultOptions, ...opt });
|
|
25
|
+
this.#engine = engine; // Store parent engine for later callbacks
|
|
26
|
+
if (this.#options.autostart) this.start();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
#checkOptionsConsistancy(options: Options): Options {
|
|
30
|
+
if (!options) throw new _.Errors.CQError(ErrorsList.NoOptionsOnRunnerInitialization);
|
|
31
|
+
return options;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async #run(): Promise<void> {
|
|
35
|
+
while (this.status === "running") {
|
|
36
|
+
await new Promise((resolve) => setTimeout(resolve, 10)); // Do not freeze the event loop with infinite loop.
|
|
37
|
+
// get the next task to run according to this runner priority
|
|
38
|
+
const task = await this.#engine.getNextTask(this.#options.priority);
|
|
39
|
+
if (task) {
|
|
40
|
+
await task.runner();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
start(): void {
|
|
46
|
+
this.status = "running";
|
|
47
|
+
this.#run();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
stop(): void {
|
|
51
|
+
this.status = "stopping";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
statistics(): Statistics {
|
|
55
|
+
const stat: Statistics = {
|
|
56
|
+
status: this.status,
|
|
57
|
+
priority: this.#options.priority,
|
|
58
|
+
};
|
|
59
|
+
return stat;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { Options, Statistics, ErrorsList } from "./interfaces";
|
|
64
|
+
export { Runner };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as _ from "../helpers";
|
|
2
|
+
|
|
3
|
+
interface Options {
|
|
4
|
+
autostart?: boolean;
|
|
5
|
+
priority: number;
|
|
6
|
+
logFunction?: _.Logs.LogFunction;
|
|
7
|
+
}
|
|
8
|
+
interface Statistics {
|
|
9
|
+
status: string;
|
|
10
|
+
priority: number;
|
|
11
|
+
}
|
|
12
|
+
type ErrorListKeys = "NoOptionsOnRunnerInitialization";
|
|
13
|
+
|
|
14
|
+
const ErrorsList: {
|
|
15
|
+
[index in ErrorListKeys]: { name: string; message: string };
|
|
16
|
+
} = {
|
|
17
|
+
NoOptionsOnRunnerInitialization: {
|
|
18
|
+
name: "NoOptionsOnRunnerInitialization",
|
|
19
|
+
message: "NoOptionsOnRunnerInitialization",
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { Priorities } from "../queue/interfaces";
|
|
24
|
+
export { Options, Statistics, ErrorsList };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// clever-queue
|
|
2
|
+
|
|
3
|
+
import * as _ from "../helpers";
|
|
4
|
+
import { Options, Statistics, ErrorsList, FunctionToExecute } from "./interfaces";
|
|
5
|
+
|
|
6
|
+
type Status = "unknown" | "initialiazing" | "running" | "stopping" | "destroying";
|
|
7
|
+
|
|
8
|
+
const defaultOptions: Options = {
|
|
9
|
+
logFunction: undefined,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
class Task {
|
|
13
|
+
status: Status = "unknown";
|
|
14
|
+
readonly #options: Options;
|
|
15
|
+
#functionToExecute: FunctionToExecute;
|
|
16
|
+
result: unknown | undefined = undefined;
|
|
17
|
+
readonly runner: () => Promise<unknown>;
|
|
18
|
+
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
resolver: (value: any | PromiseLike<any>) => void;
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
rejecter: (reason?: any) => void;
|
|
23
|
+
|
|
24
|
+
#defaultResolver(): void {
|
|
25
|
+
throw new _.Errors.CQError(ErrorsList.TaskRunnerNotInitialized);
|
|
26
|
+
}
|
|
27
|
+
#defaultRejecter(): void {
|
|
28
|
+
throw new _.Errors.CQError(ErrorsList.TaskRunnerNotInitialized);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
constructor(function_: FunctionToExecute, opt: Options) {
|
|
32
|
+
this.status = "initialiazing";
|
|
33
|
+
this.#options = this.#checkOptionsConsistancy({ ...defaultOptions, ...opt });
|
|
34
|
+
|
|
35
|
+
if (typeof function_ !== "function") throw new _.Errors.CQError(ErrorsList.FunctionIsNotAFunction);
|
|
36
|
+
|
|
37
|
+
this.resolver = this.#defaultResolver;
|
|
38
|
+
this.rejecter = this.#defaultRejecter;
|
|
39
|
+
this.#functionToExecute = function_;
|
|
40
|
+
|
|
41
|
+
this.runner = async (): Promise<void> => {
|
|
42
|
+
this.status = "running";
|
|
43
|
+
// console.log("running Task");
|
|
44
|
+
this.result = await this.#functionToExecute();
|
|
45
|
+
// console.log("task runned", this.result);
|
|
46
|
+
this.status = "stopping";
|
|
47
|
+
this.resolver(this.result);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
#checkOptionsConsistancy(options: Options): Options {
|
|
52
|
+
if (!options) throw new _.Errors.CQError(ErrorsList.NoOptionsOnTaskInitialization);
|
|
53
|
+
return options;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
statistics(): Statistics {
|
|
57
|
+
const stat: Statistics = {
|
|
58
|
+
status: this.status,
|
|
59
|
+
};
|
|
60
|
+
return stat;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { Options, Statistics, ErrorsList, FunctionToExecute } from "./interfaces";
|
|
65
|
+
export { Task };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as _ from "../helpers";
|
|
2
|
+
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
+
type FunctionToExecute = (...arguments_: any[]) => Promise<any> | void;
|
|
5
|
+
|
|
6
|
+
interface Options {
|
|
7
|
+
timeout?: number;
|
|
8
|
+
logFunction?: _.Logs.LogFunction;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface Statistics {
|
|
12
|
+
status: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type ErrorListKeys = "NoOptionsOnTaskInitialization" | "FunctionIsNotAFunction" | "TaskRunnerNotInitialized";
|
|
16
|
+
|
|
17
|
+
const ErrorsList: {
|
|
18
|
+
[index in ErrorListKeys]: { name: string; message: string };
|
|
19
|
+
} = {
|
|
20
|
+
NoOptionsOnTaskInitialization: {
|
|
21
|
+
name: "NoOptionsOnTaskInitialization",
|
|
22
|
+
message: "NoOptionsOnTaskInitialization",
|
|
23
|
+
},
|
|
24
|
+
FunctionIsNotAFunction: {
|
|
25
|
+
name: "FunctionIsNotAFunction",
|
|
26
|
+
message: "FunctionIsNotAFunction",
|
|
27
|
+
},
|
|
28
|
+
TaskRunnerNotInitialized: {
|
|
29
|
+
name: "TaskRunnerNotInitialized",
|
|
30
|
+
message: "TaskRunnerNotInitialized",
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export { Options, Statistics, ErrorsList, FunctionToExecute };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "nodenext",
|
|
4
|
+
"moduleResolution":"nodenext",
|
|
5
|
+
"esModuleInterop": true,
|
|
6
|
+
"target": "es2022",
|
|
7
|
+
"sourceMap": true,
|
|
8
|
+
"outDir": "../dist",
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"lib": [
|
|
11
|
+
"es2022"
|
|
12
|
+
],
|
|
13
|
+
"strict": true,
|
|
14
|
+
"useUnknownInCatchVariables": true,
|
|
15
|
+
"noImplicitAny": true,
|
|
16
|
+
"strictNullChecks": true,
|
|
17
|
+
"strictFunctionTypes": true,
|
|
18
|
+
"strictBindCallApply": true,
|
|
19
|
+
"strictPropertyInitialization": true,
|
|
20
|
+
"noImplicitThis": true,
|
|
21
|
+
"alwaysStrict": true,
|
|
22
|
+
"forceConsistentCasingInFileNames": true
|
|
23
|
+
},
|
|
24
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
25
|
+
"display": "Recommended"
|
|
26
|
+
}
|
|
27
|
+
|
|
@@ -0,0 +1,92 @@
|
|
|
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: 3,
|
|
8
|
+
logFunction: undefined,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
describe("Scheduler Unit Tests", () => {
|
|
12
|
+
it("Priority Test", () => {
|
|
13
|
+
const engine = CleverQueue.createEngine(engineOptions);
|
|
14
|
+
const queue1 = engine.createQueue({
|
|
15
|
+
name: "A",
|
|
16
|
+
priority: CleverQueue.Queue.Priorities.Absolute,
|
|
17
|
+
weight: 50,
|
|
18
|
+
});
|
|
19
|
+
for (let index = 0; index < 100; index++) queue1.enqueue(engine.createTask(() => {}, {}));
|
|
20
|
+
const queue2 = engine.createQueue({
|
|
21
|
+
name: "B",
|
|
22
|
+
priority: CleverQueue.Queue.Priorities.Standard,
|
|
23
|
+
weight: 50,
|
|
24
|
+
});
|
|
25
|
+
for (let index = 0; index < 100; index++) queue2.enqueue(engine.createTask(() => {}, {}));
|
|
26
|
+
const queue3 = engine.createQueue({
|
|
27
|
+
name: "C",
|
|
28
|
+
priority: CleverQueue.Queue.Priorities.BestEffort,
|
|
29
|
+
weight: 50,
|
|
30
|
+
});
|
|
31
|
+
for (let index = 0; index < 100; index++) queue3.enqueue(engine.createTask(() => {}, {}));
|
|
32
|
+
|
|
33
|
+
const engineStatistics = engine.statistics();
|
|
34
|
+
assert.equal(engineStatistics.engine.queues, 3);
|
|
35
|
+
engine.stop();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("Weighted Test", () => {
|
|
39
|
+
const engine = CleverQueue.createEngine(engineOptions);
|
|
40
|
+
const queue1 = engine.createQueue({
|
|
41
|
+
name: "A",
|
|
42
|
+
priority: CleverQueue.Queue.Priorities.Absolute,
|
|
43
|
+
weight: 80,
|
|
44
|
+
});
|
|
45
|
+
for (let index = 0; index < 100; index++) queue1.enqueue(engine.createTask(() => {}, {}));
|
|
46
|
+
const queue2 = engine.createQueue({
|
|
47
|
+
name: "B",
|
|
48
|
+
priority: CleverQueue.Queue.Priorities.Absolute,
|
|
49
|
+
weight: 50,
|
|
50
|
+
});
|
|
51
|
+
for (let index = 0; index < 100; index++) queue2.enqueue(engine.createTask(() => {}, {}));
|
|
52
|
+
const queue3 = engine.createQueue({
|
|
53
|
+
name: "C",
|
|
54
|
+
priority: CleverQueue.Queue.Priorities.Absolute,
|
|
55
|
+
weight: 20,
|
|
56
|
+
});
|
|
57
|
+
for (let index = 0; index < 100; index++) queue3.enqueue(engine.createTask(() => {}, {}));
|
|
58
|
+
|
|
59
|
+
const engineStatistics = engine.statistics();
|
|
60
|
+
assert.equal(engineStatistics.engine.queues, 3);
|
|
61
|
+
engine.stop();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("Combine Test", () => {
|
|
65
|
+
const engine = CleverQueue.createEngine(engineOptions);
|
|
66
|
+
|
|
67
|
+
const queue1 = engine.createQueue({
|
|
68
|
+
name: "A - Absolute - 80",
|
|
69
|
+
priority: CleverQueue.Queue.Priorities.Absolute,
|
|
70
|
+
weight: 80,
|
|
71
|
+
});
|
|
72
|
+
for (let index = 0; index < 100; index++) queue1.enqueue(engine.createTask(() => {}, {}));
|
|
73
|
+
|
|
74
|
+
const queue2 = engine.createQueue({
|
|
75
|
+
name: "B - Standard - 50",
|
|
76
|
+
priority: CleverQueue.Queue.Priorities.Standard,
|
|
77
|
+
weight: 50,
|
|
78
|
+
});
|
|
79
|
+
for (let index = 0; index < 100; index++) queue2.enqueue(engine.createTask(() => {}, {}));
|
|
80
|
+
|
|
81
|
+
const queue3 = engine.createQueue({
|
|
82
|
+
name: "C- Standard - 20",
|
|
83
|
+
priority: CleverQueue.Queue.Priorities.Standard,
|
|
84
|
+
weight: 20,
|
|
85
|
+
});
|
|
86
|
+
for (let index = 0; index < 100; index++) queue3.enqueue(engine.createTask(() => {}, {}));
|
|
87
|
+
|
|
88
|
+
const engineStatistics = engine.statistics();
|
|
89
|
+
assert.equal(engineStatistics.engine.queues, 3);
|
|
90
|
+
engine.stop();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
describe("Engine Class Unit Tests", () => {
|
|
7
|
+
it("Successfull Initialisation without any option (use hardcoded default options)", () => {
|
|
8
|
+
const engine = CleverQueue.createEngine();
|
|
9
|
+
const statistics = engine.statistics();
|
|
10
|
+
assert.equal(statistics.engine.runners, 1);
|
|
11
|
+
assert.equal(statistics.engine.queues, 0);
|
|
12
|
+
engine.stop();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("Exception with stupid bestEffortRunners Options", () => {
|
|
16
|
+
assert.throws(
|
|
17
|
+
() =>
|
|
18
|
+
CleverQueue.createEngine({
|
|
19
|
+
bestEffortRunners: -1,
|
|
20
|
+
}),
|
|
21
|
+
{ name: CleverQueue.Engine.ErrorsList.bestEffortRunnersOptionMustBeGreaterThanZero.name },
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("Successfull Initialisation with 3 Runners", () => {
|
|
26
|
+
const engineOptions = {
|
|
27
|
+
bestEffortRunners: 3,
|
|
28
|
+
};
|
|
29
|
+
const engine = CleverQueue.createEngine(engineOptions);
|
|
30
|
+
const statistics = engine.statistics();
|
|
31
|
+
assert.equal(statistics.engine.runners, engineOptions.bestEffortRunners);
|
|
32
|
+
assert.equal(statistics.engine.queues, 0);
|
|
33
|
+
engine.stop();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
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: 3,
|
|
8
|
+
logFunction: undefined,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
describe("Queue Class Unit Tests", () => {
|
|
12
|
+
it("Successfull Initialisation without any option (use hardcoded default options)", () => {
|
|
13
|
+
const engine = CleverQueue.createEngine();
|
|
14
|
+
const statistics = engine.statistics();
|
|
15
|
+
assert.equal(statistics.engine.runners, 1);
|
|
16
|
+
assert.equal(statistics.engine.queues, 0);
|
|
17
|
+
engine.stop();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("Successfull Initialisation", () => {
|
|
21
|
+
const engine = CleverQueue.createEngine(engineOptions);
|
|
22
|
+
const queueOptions = {
|
|
23
|
+
priority: CleverQueue.Queue.Priorities.Standard,
|
|
24
|
+
weight: 50,
|
|
25
|
+
};
|
|
26
|
+
const queue = engine.createQueue(queueOptions);
|
|
27
|
+
const engineStatistics = engine.statistics();
|
|
28
|
+
assert.equal(engineStatistics.engine.queues, 1);
|
|
29
|
+
const queueStatistics = queue.statistics();
|
|
30
|
+
assert.equal(queueStatistics.priority, queueOptions.priority);
|
|
31
|
+
assert.equal(queueStatistics.weight, queueOptions.weight);
|
|
32
|
+
engine.stop();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
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: 3,
|
|
8
|
+
logFunction: undefined,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const task = async (string_) => {
|
|
12
|
+
// console.log(string_, "Start", new Date());
|
|
13
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
14
|
+
// console.log(string_, "End", new Date());
|
|
15
|
+
return string_;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
describe("Scheduler Unit Tests", () => {
|
|
19
|
+
it("Exception if function passed is not a function (but a result of an executed function)", () => {
|
|
20
|
+
const engine = CleverQueue.createEngine(engineOptions);
|
|
21
|
+
const queue1 = engine.createQueue({
|
|
22
|
+
name: "A",
|
|
23
|
+
priority: CleverQueue.Queue.Priorities.Absolute,
|
|
24
|
+
weight: 50,
|
|
25
|
+
});
|
|
26
|
+
assert.rejects(
|
|
27
|
+
async () => {
|
|
28
|
+
const myTask = engine.createTask(task("myTask"), {});
|
|
29
|
+
await queue1.enqueue(myTask);
|
|
30
|
+
},
|
|
31
|
+
{ name: CleverQueue.Task.ErrorsList.FunctionIsNotAFunction.name },
|
|
32
|
+
);
|
|
33
|
+
engine.stop();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("Priority Test", () => {
|
|
37
|
+
const engine = CleverQueue.createEngine(engineOptions);
|
|
38
|
+
const queue1 = engine.createQueue({
|
|
39
|
+
name: "A",
|
|
40
|
+
priority: CleverQueue.Queue.Priorities.Absolute,
|
|
41
|
+
weight: 50,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
for (let index = 0; index < 8; index++) queue1.enqueue(engine.createTask(() => task("Task " + index), {}));
|
|
45
|
+
|
|
46
|
+
const engineStatistics = engine.statistics();
|
|
47
|
+
assert.equal(engineStatistics.engine.queues, 1);
|
|
48
|
+
engine.stop();
|
|
49
|
+
});
|
|
50
|
+
});
|