@alanszp/queue 9.2.6 → 9.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/dist/jobsManagement/commands/asyncCreationCommands.d.ts +7 -0
- package/dist/jobsManagement/commands/asyncCreationCommands.js +45 -0
- package/dist/jobsManagement/commands/asyncCreationCommands.js.map +1 -0
- package/dist/jobsManagement/commands/getCommands.d.ts +8 -0
- package/dist/jobsManagement/commands/getCommands.js +47 -0
- package/dist/jobsManagement/commands/getCommands.js.map +1 -0
- package/dist/jobsManagement/commands/workerHealthCommand.d.ts +2 -0
- package/dist/jobsManagement/commands/workerHealthCommand.js +10 -0
- package/dist/jobsManagement/commands/workerHealthCommand.js.map +1 -0
- package/dist/jobsManagement/index.d.ts +6 -0
- package/dist/jobsManagement/index.js +19 -0
- package/dist/jobsManagement/index.js.map +1 -0
- package/dist/jobsManagement/inputs/CreateAsyncJobInput.d.ts +11 -0
- package/dist/jobsManagement/inputs/CreateAsyncJobInput.js +58 -0
- package/dist/jobsManagement/inputs/CreateAsyncJobInput.js.map +1 -0
- package/dist/jobsManagement/inputs/GetJobInput.d.ts +6 -0
- package/dist/jobsManagement/inputs/GetJobInput.js +44 -0
- package/dist/jobsManagement/inputs/GetJobInput.js.map +1 -0
- package/dist/jobsManagement/inputs/SearchJobsInput.d.ts +14 -0
- package/dist/jobsManagement/inputs/SearchJobsInput.js +61 -0
- package/dist/jobsManagement/inputs/SearchJobsInput.js.map +1 -0
- package/dist/reporter/totalCount/ITotalCountReporter.d.ts +5 -0
- package/dist/reporter/totalCount/ITotalCountReporter.js +3 -0
- package/dist/reporter/totalCount/ITotalCountReporter.js.map +1 -0
- package/dist/reporter/totalCount/JobTotalCountReporter.d.ts +12 -0
- package/dist/reporter/totalCount/JobTotalCountReporter.js +29 -0
- package/dist/reporter/totalCount/JobTotalCountReporter.js.map +1 -0
- package/dist/reporter/totalCount/MockTotalCountReporter.d.ts +8 -0
- package/dist/reporter/totalCount/MockTotalCountReporter.js +21 -0
- package/dist/reporter/totalCount/MockTotalCountReporter.js.map +1 -0
- package/dist/worker/workerRepository.d.ts +2 -2
- package/dist/worker/workerRepository.js +7 -2
- package/dist/worker/workerRepository.js.map +1 -1
- package/package.json +4 -2
- package/src/jobsManagement/commands/asyncCreationCommands.ts +58 -0
- package/src/jobsManagement/commands/getCommands.ts +57 -0
- package/src/jobsManagement/commands/workerHealthCommand.ts +10 -0
- package/src/jobsManagement/index.ts +6 -0
- package/src/jobsManagement/inputs/CreateAsyncJobInput.ts +37 -0
- package/src/jobsManagement/inputs/GetJobInput.ts +17 -0
- package/src/jobsManagement/inputs/SearchJobsInput.ts +45 -0
- package/src/reporter/totalCount/ITotalCountReporter.ts +5 -0
- package/src/reporter/totalCount/JobTotalCountReporter.ts +37 -0
- package/src/reporter/totalCount/MockTotalCountReporter.ts +20 -0
- package/src/worker/workerRepository.ts +13 -5
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ILogger } from "@alanszp/logger";
|
|
2
|
+
import { BaseModel } from "@alanszp/validations";
|
|
3
|
+
import { CreateAsyncJobInput } from "../inputs/CreateAsyncJobInput";
|
|
4
|
+
import { Queue } from "../../queue/queue";
|
|
5
|
+
import { Job } from "../../types";
|
|
6
|
+
export declare function asyncJobCreationCommand<QueueInputBody, RealInput extends BaseModel & QueueInputBody, AsyncInput extends CreateAsyncJobInput<RealInput>>(logger: ILogger, queue: Queue<QueueInputBody>, input: AsyncInput): Promise<Job<QueueInputBody>>;
|
|
7
|
+
export declare function immediateExecutionJobCreationCommand<QueueInputBody, RealInput extends QueueInputBody & BaseModel>(logger: ILogger, queue: Queue<QueueInputBody>, input: RealInput): Promise<Job<QueueInputBody>>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.immediateExecutionJobCreationCommand = exports.asyncJobCreationCommand = void 0;
|
|
13
|
+
function asyncJobCreationCommand(logger, queue, input) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const child = logger.child({
|
|
16
|
+
input,
|
|
17
|
+
queueName: queue.getName(),
|
|
18
|
+
});
|
|
19
|
+
child.info("worker.async.create_job.starting");
|
|
20
|
+
yield input.validate();
|
|
21
|
+
child.debug("worker.async.create_job.validated");
|
|
22
|
+
const job = yield queue.publishJob(input.asyncInput, {
|
|
23
|
+
delay: input.getDelayInMs(),
|
|
24
|
+
});
|
|
25
|
+
child.debug("worker.async.create_job.succeed", { jobId: job.id });
|
|
26
|
+
return job;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
exports.asyncJobCreationCommand = asyncJobCreationCommand;
|
|
30
|
+
function immediateExecutionJobCreationCommand(logger, queue, input) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const child = logger.child({
|
|
33
|
+
input,
|
|
34
|
+
queueName: queue.getName(),
|
|
35
|
+
});
|
|
36
|
+
child.info("worker.async.create_job.starting");
|
|
37
|
+
yield input.validate();
|
|
38
|
+
child.debug("worker.async.create_job.validated");
|
|
39
|
+
const job = yield queue.publishJob(input);
|
|
40
|
+
child.debug("worker.async.create_job.succeed", { jobId: job.id });
|
|
41
|
+
return job;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
exports.immediateExecutionJobCreationCommand = immediateExecutionJobCreationCommand;
|
|
45
|
+
//# sourceMappingURL=asyncCreationCommands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asyncCreationCommands.js","sourceRoot":"","sources":["../../../src/jobsManagement/commands/asyncCreationCommands.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,SAAsB,uBAAuB,CAK3C,MAAe,EACf,KAA4B,EAC5B,KAAiB;;QAEjB,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;YACzB,KAAK;YACL,SAAS,EAAE,KAAK,CAAC,OAAO,EAAE;SAC3B,CAAC,CAAC;QAEH,KAAK,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;QAC/C,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAC;QAEvB,KAAK,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;QAEjD,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,UAAU,EAAE;YACnD,KAAK,EAAE,KAAK,CAAC,YAAY,EAAE;SAC5B,CAAC,CAAC;QAEH,KAAK,CAAC,KAAK,CAAC,iCAAiC,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;QAElE,OAAO,GAAG,CAAC;IACb,CAAC;CAAA;AA1BD,0DA0BC;AAED,SAAsB,oCAAoC,CAIxD,MAAe,EACf,KAA4B,EAC5B,KAAgB;;QAEhB,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;YACzB,KAAK;YACL,SAAS,EAAE,KAAK,CAAC,OAAO,EAAE;SAC3B,CAAC,CAAC;QAEH,KAAK,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;QAC/C,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAC;QAEvB,KAAK,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;QAEjD,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAE1C,KAAK,CAAC,KAAK,CAAC,iCAAiC,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;QAElE,OAAO,GAAG,CAAC;IACb,CAAC;CAAA;AAvBD,oFAuBC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ILogger } from "@alanszp/logger";
|
|
2
|
+
import { GetJobInput } from "../inputs/GetJobInput";
|
|
3
|
+
import { SearchJobsInput } from "../inputs/SearchJobsInput";
|
|
4
|
+
import { ListResult } from "@alanszp/core";
|
|
5
|
+
import { Queue } from "../../queue/queue";
|
|
6
|
+
import { Job } from "../../types";
|
|
7
|
+
export declare function getJobStatus<QueueInputBody, ReturnValue>(logger: ILogger, queue: Queue<QueueInputBody, ReturnValue>, input: GetJobInput): Promise<Job<QueueInputBody, ReturnValue> | undefined>;
|
|
8
|
+
export declare function searchJobsCommand<QueueInputBody, ReturnValue>(logger: ILogger, queue: Queue<QueueInputBody, ReturnValue>, input: SearchJobsInput): Promise<ListResult<Job<QueueInputBody, ReturnValue>>>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.searchJobsCommand = exports.getJobStatus = void 0;
|
|
13
|
+
function getJobStatus(logger, queue, input) {
|
|
14
|
+
var _a;
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const child = logger.child({
|
|
17
|
+
input,
|
|
18
|
+
queueName: queue.getName(),
|
|
19
|
+
});
|
|
20
|
+
child.info("worker.get_job.starting");
|
|
21
|
+
yield input.validate();
|
|
22
|
+
child.debug("worker.get_job.validated");
|
|
23
|
+
const job = yield queue.getJobOrFail(input.jobId);
|
|
24
|
+
child.info("worker.get_job.succeed", { jobId: (_a = job === null || job === void 0 ? void 0 : job.id) !== null && _a !== void 0 ? _a : null });
|
|
25
|
+
return job;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
exports.getJobStatus = getJobStatus;
|
|
29
|
+
function searchJobsCommand(logger, queue, input) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const child = logger.child({
|
|
32
|
+
input,
|
|
33
|
+
queueName: queue.getName(),
|
|
34
|
+
});
|
|
35
|
+
child.info("worker.get_job.starting");
|
|
36
|
+
yield input.validate();
|
|
37
|
+
child.debug("worker.get_job.validated");
|
|
38
|
+
const jobs = yield queue.getJobsAndCountByStatus(input.status, input.page, input.pageSize);
|
|
39
|
+
child.info("worker.get_job.succeed", {
|
|
40
|
+
jobTotal: jobs.total,
|
|
41
|
+
jobInPage: jobs.elements.length,
|
|
42
|
+
});
|
|
43
|
+
return jobs;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
exports.searchJobsCommand = searchJobsCommand;
|
|
47
|
+
//# sourceMappingURL=getCommands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCommands.js","sourceRoot":"","sources":["../../../src/jobsManagement/commands/getCommands.ts"],"names":[],"mappings":";;;;;;;;;;;;AAOA,SAAsB,YAAY,CAChC,MAAe,EACf,KAAyC,EACzC,KAAkB;;;QAElB,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;YACzB,KAAK;YACL,SAAS,EAAE,KAAK,CAAC,OAAO,EAAE;SAC3B,CAAC,CAAC;QAEH,KAAK,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;QACtC,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAC;QAEvB,KAAK,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAExC,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAElD,KAAK,CAAC,IAAI,CAAC,wBAAwB,EAAE,EAAE,KAAK,EAAE,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,EAAE,mCAAI,IAAI,EAAE,CAAC,CAAC;QAEjE,OAAO,GAAG,CAAC;;CACZ;AApBD,oCAoBC;AAED,SAAsB,iBAAiB,CACrC,MAAe,EACf,KAAyC,EACzC,KAAsB;;QAEtB,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;YACzB,KAAK;YACL,SAAS,EAAE,KAAK,CAAC,OAAO,EAAE;SAC3B,CAAC,CAAC;QAEH,KAAK,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;QACtC,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAC;QAEvB,KAAK,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAExC,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,uBAAuB,CAC9C,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,QAAQ,CACf,CAAC;QAEF,KAAK,CAAC,IAAI,CAAC,wBAAwB,EAAE;YACnC,QAAQ,EAAE,IAAI,CAAC,KAAK;YACpB,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM;SAChC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;CAAA;AA3BD,8CA2BC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.workerHealthCommand = void 0;
|
|
4
|
+
const workerRepository_1 = require("../../worker/workerRepository");
|
|
5
|
+
function workerHealthCommand() {
|
|
6
|
+
const statuses = workerRepository_1.WorkerRepository.Instance.getWorkerStatuses();
|
|
7
|
+
return statuses;
|
|
8
|
+
}
|
|
9
|
+
exports.workerHealthCommand = workerHealthCommand;
|
|
10
|
+
//# sourceMappingURL=workerHealthCommand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workerHealthCommand.js","sourceRoot":"","sources":["../../../src/jobsManagement/commands/workerHealthCommand.ts"],"names":[],"mappings":";;;AAAA,oEAGuC;AAEvC,SAAgB,mBAAmB;IACjC,MAAM,QAAQ,GAAG,mCAAgB,CAAC,QAAQ,CAAC,iBAAiB,EAAE,CAAC;IAE/D,OAAO,QAAQ,CAAC;AAClB,CAAC;AAJD,kDAIC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./inputs/CreateAsyncJobInput";
|
|
2
|
+
export * from "./inputs/GetJobInput";
|
|
3
|
+
export * from "./inputs/SearchJobsInput";
|
|
4
|
+
export * from "./commands/asyncCreationCommands";
|
|
5
|
+
export * from "./commands/getCommands";
|
|
6
|
+
export * from "./commands/workerHealthCommand";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./inputs/CreateAsyncJobInput"), exports);
|
|
14
|
+
__exportStar(require("./inputs/GetJobInput"), exports);
|
|
15
|
+
__exportStar(require("./inputs/SearchJobsInput"), exports);
|
|
16
|
+
__exportStar(require("./commands/asyncCreationCommands"), exports);
|
|
17
|
+
__exportStar(require("./commands/getCommands"), exports);
|
|
18
|
+
__exportStar(require("./commands/workerHealthCommand"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/jobsManagement/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+DAA6C;AAC7C,uDAAqC;AACrC,2DAAyC;AACzC,mEAAiD;AACjD,yDAAuC;AACvC,iEAA+C"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseModel } from "@alanszp/validations";
|
|
2
|
+
export interface CreateAsyncJobQueryParams {
|
|
3
|
+
executeOn?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare class CreateAsyncJobInput<RealInput extends BaseModel> extends BaseModel {
|
|
6
|
+
executeOn?: string;
|
|
7
|
+
asyncInput: RealInput;
|
|
8
|
+
constructor(asyncParams: CreateAsyncJobQueryParams, asyncInput: RealInput);
|
|
9
|
+
validate(): Promise<void>;
|
|
10
|
+
getDelayInMs(): number | undefined;
|
|
11
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.CreateAsyncJobInput = void 0;
|
|
22
|
+
const class_validator_1 = require("class-validator");
|
|
23
|
+
const validations_1 = require("@alanszp/validations");
|
|
24
|
+
const date_fns_1 = require("date-fns");
|
|
25
|
+
class CreateAsyncJobInput extends validations_1.BaseModel {
|
|
26
|
+
constructor(asyncParams, asyncInput) {
|
|
27
|
+
super();
|
|
28
|
+
this.executeOn = asyncParams.executeOn;
|
|
29
|
+
this.asyncInput = asyncInput;
|
|
30
|
+
}
|
|
31
|
+
validate() {
|
|
32
|
+
const _super = Object.create(null, {
|
|
33
|
+
validate: { get: () => super.validate }
|
|
34
|
+
});
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
yield _super.validate.call(this);
|
|
37
|
+
yield this.asyncInput.validate();
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
getDelayInMs() {
|
|
41
|
+
if (!this.executeOn)
|
|
42
|
+
return undefined;
|
|
43
|
+
const date = new Date(this.executeOn);
|
|
44
|
+
const delay = (0, date_fns_1.differenceInMilliseconds)(date, new Date());
|
|
45
|
+
return delay > 0 ? delay : undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, class_validator_1.IsDateString)(),
|
|
50
|
+
(0, class_validator_1.IsOptional)(),
|
|
51
|
+
__metadata("design:type", String)
|
|
52
|
+
], CreateAsyncJobInput.prototype, "executeOn", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, class_validator_1.IsDefined)(),
|
|
55
|
+
__metadata("design:type", Object)
|
|
56
|
+
], CreateAsyncJobInput.prototype, "asyncInput", void 0);
|
|
57
|
+
exports.CreateAsyncJobInput = CreateAsyncJobInput;
|
|
58
|
+
//# sourceMappingURL=CreateAsyncJobInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateAsyncJobInput.js","sourceRoot":"","sources":["../../../src/jobsManagement/inputs/CreateAsyncJobInput.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,qDAAsE;AACtE,sDAAiD;AACjD,uCAAoD;AAMpD,MAAa,mBAEX,SAAQ,uBAAS;IAQjB,YAAY,WAAsC,EAAE,UAAqB;QACvE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,GAAG,WAAW,CAAC,SAAS,CAAC;QACvC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAEK,QAAQ;;;;;YACZ,MAAM,OAAM,QAAQ,WAAE,CAAC;YAEvB,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;QACnC,CAAC;KAAA;IAED,YAAY;QACV,IAAI,CAAC,IAAI,CAAC,SAAS;YAAE,OAAO,SAAS,CAAC;QACtC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACtC,MAAM,KAAK,GAAG,IAAA,mCAAwB,EAAC,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;QACzD,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACvC,CAAC;CACF;AAvBC;IAFC,IAAA,8BAAY,GAAE;IACd,IAAA,4BAAU,GAAE;;sDACa;AAG1B;IADC,IAAA,2BAAS,GAAE;;uDACiB;AAR/B,kDA4BC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.GetJobInput = void 0;
|
|
22
|
+
const class_validator_1 = require("class-validator");
|
|
23
|
+
const validations_1 = require("@alanszp/validations");
|
|
24
|
+
class GetJobInput extends validations_1.BaseModel {
|
|
25
|
+
constructor(jobId) {
|
|
26
|
+
super();
|
|
27
|
+
this.jobId = jobId;
|
|
28
|
+
}
|
|
29
|
+
validate() {
|
|
30
|
+
const _super = Object.create(null, {
|
|
31
|
+
validate: { get: () => super.validate }
|
|
32
|
+
});
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
yield _super.validate.call(this);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, class_validator_1.IsDefined)(),
|
|
40
|
+
(0, class_validator_1.IsString)(),
|
|
41
|
+
__metadata("design:type", String)
|
|
42
|
+
], GetJobInput.prototype, "jobId", void 0);
|
|
43
|
+
exports.GetJobInput = GetJobInput;
|
|
44
|
+
//# sourceMappingURL=GetJobInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GetJobInput.js","sourceRoot":"","sources":["../../../src/jobsManagement/inputs/GetJobInput.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,qDAAsD;AACtD,sDAAiD;AAEjD,MAAa,WAAY,SAAQ,uBAAS;IAKxC,YAAY,KAAa;QACvB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAEK,QAAQ;;;;;YACZ,MAAM,OAAM,QAAQ,WAAE,CAAC;QACzB,CAAC;KAAA;CACF;AAVC;IAFC,IAAA,2BAAS,GAAE;IACX,IAAA,0BAAQ,GAAE;;0CACU;AAHvB,kCAaC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseModel } from "@alanszp/validations";
|
|
2
|
+
import { JobTypeEnum } from "../../types";
|
|
3
|
+
export interface SearchJobInputProps {
|
|
4
|
+
status: JobTypeEnum[];
|
|
5
|
+
page?: string | number;
|
|
6
|
+
pageSize?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class SearchJobsInput extends BaseModel {
|
|
9
|
+
status: JobTypeEnum[];
|
|
10
|
+
page: number;
|
|
11
|
+
pageSize: number;
|
|
12
|
+
constructor({ status, page, pageSize }: SearchJobInputProps);
|
|
13
|
+
validate(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.SearchJobsInput = void 0;
|
|
22
|
+
const class_validator_1 = require("class-validator");
|
|
23
|
+
const validations_1 = require("@alanszp/validations");
|
|
24
|
+
const types_1 = require("../../types");
|
|
25
|
+
const core_1 = require("@alanszp/core");
|
|
26
|
+
class SearchJobsInput extends validations_1.BaseModel {
|
|
27
|
+
constructor({ status, page, pageSize }) {
|
|
28
|
+
super();
|
|
29
|
+
this.status = status;
|
|
30
|
+
(0, core_1.assignPaginableKeys)(this, { page, pageSize });
|
|
31
|
+
}
|
|
32
|
+
validate() {
|
|
33
|
+
const _super = Object.create(null, {
|
|
34
|
+
validate: { get: () => super.validate }
|
|
35
|
+
});
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
yield _super.validate.call(this);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, class_validator_1.IsDefined)(),
|
|
43
|
+
(0, class_validator_1.IsArray)(),
|
|
44
|
+
(0, class_validator_1.IsEnum)(types_1.JobTypeEnum, { each: true }),
|
|
45
|
+
__metadata("design:type", Array)
|
|
46
|
+
], SearchJobsInput.prototype, "status", void 0);
|
|
47
|
+
__decorate([
|
|
48
|
+
(0, class_validator_1.IsDefined)(),
|
|
49
|
+
(0, class_validator_1.IsNumber)(),
|
|
50
|
+
(0, class_validator_1.Min)(1),
|
|
51
|
+
__metadata("design:type", Number)
|
|
52
|
+
], SearchJobsInput.prototype, "page", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, class_validator_1.IsDefined)(),
|
|
55
|
+
(0, class_validator_1.IsNumber)(),
|
|
56
|
+
(0, class_validator_1.Min)(1),
|
|
57
|
+
(0, class_validator_1.Max)(100),
|
|
58
|
+
__metadata("design:type", Number)
|
|
59
|
+
], SearchJobsInput.prototype, "pageSize", void 0);
|
|
60
|
+
exports.SearchJobsInput = SearchJobsInput;
|
|
61
|
+
//# sourceMappingURL=SearchJobsInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchJobsInput.js","sourceRoot":"","sources":["../../../src/jobsManagement/inputs/SearchJobsInput.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,qDAOyB;AACzB,sDAAiD;AACjD,uCAA0C;AAC1C,wCAAoD;AAQpD,MAAa,eAAgB,SAAQ,uBAAS;IAiB5C,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAuB;QACzD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAA,0BAAmB,EAAC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IAChD,CAAC;IAEK,QAAQ;;;;;YACZ,MAAM,OAAM,QAAQ,WAAE,CAAC;QACzB,CAAC;KAAA;CACF;AAtBC;IAHC,IAAA,2BAAS,GAAE;IACX,IAAA,yBAAO,GAAE;IACT,IAAA,wBAAM,EAAC,mBAAW,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;;+CACP;AAK7B;IAHC,IAAA,2BAAS,GAAE;IACX,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,CAAC,CAAC;;6CACa;AAMpB;IAJC,IAAA,2BAAS,GAAE;IACX,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,CAAC,CAAC;IACN,IAAA,qBAAG,EAAC,GAAG,CAAC;;iDACe;AAf1B,0CA0BC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ITotalCountReporter.js","sourceRoot":"","sources":["../../../src/reporter/totalCount/ITotalCountReporter.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Job } from "../../types";
|
|
2
|
+
import { ITotalCountReporter } from "./ITotalCountReporter";
|
|
3
|
+
export declare class JobTotalCountReporter<JobInstance extends Job> implements ITotalCountReporter {
|
|
4
|
+
private total;
|
|
5
|
+
private current;
|
|
6
|
+
private job;
|
|
7
|
+
constructor(job: JobInstance);
|
|
8
|
+
setTotal(total: number): void;
|
|
9
|
+
increment(n?: number): void;
|
|
10
|
+
reset(value?: number): void;
|
|
11
|
+
report(): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JobTotalCountReporter = void 0;
|
|
4
|
+
class JobTotalCountReporter {
|
|
5
|
+
constructor(job) {
|
|
6
|
+
this.total = 1;
|
|
7
|
+
this.current = 0;
|
|
8
|
+
this.job = job;
|
|
9
|
+
}
|
|
10
|
+
setTotal(total) {
|
|
11
|
+
this.total = total;
|
|
12
|
+
this.reset();
|
|
13
|
+
}
|
|
14
|
+
increment(n) {
|
|
15
|
+
this.current += n !== null && n !== void 0 ? n : 1;
|
|
16
|
+
this.report();
|
|
17
|
+
}
|
|
18
|
+
reset(value) {
|
|
19
|
+
this.current = value !== null && value !== void 0 ? value : 0;
|
|
20
|
+
this.report();
|
|
21
|
+
}
|
|
22
|
+
report() {
|
|
23
|
+
this.job
|
|
24
|
+
.updateProgress({ total: this.total, current: this.current })
|
|
25
|
+
.catch(() => { });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.JobTotalCountReporter = JobTotalCountReporter;
|
|
29
|
+
//# sourceMappingURL=JobTotalCountReporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JobTotalCountReporter.js","sourceRoot":"","sources":["../../../src/reporter/totalCount/JobTotalCountReporter.ts"],"names":[],"mappings":";;;AAGA,MAAa,qBAAqB;IAShC,YAAY,GAAgB;QANpB,UAAK,GAAG,CAAC,CAAC;QAEV,YAAO,GAAG,CAAC,CAAC;QAKlB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,QAAQ,CAAC,KAAa;QACpB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAED,SAAS,CAAC,CAAU;QAClB,IAAI,CAAC,OAAO,IAAI,CAAC,aAAD,CAAC,cAAD,CAAC,GAAI,CAAC,CAAC;QACvB,IAAI,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,KAAc;QAClB,IAAI,CAAC,OAAO,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,CAAC,CAAC;QAC1B,IAAI,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,GAAG;aACL,cAAc,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;aAC5D,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACrB,CAAC;CACF;AAjCD,sDAiCC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ITotalCountReporter } from "./ITotalCountReporter";
|
|
2
|
+
export declare class MockTotalCountReporter implements ITotalCountReporter {
|
|
3
|
+
private total;
|
|
4
|
+
private progress;
|
|
5
|
+
setTotal(total: number): void;
|
|
6
|
+
increment(n?: number): void;
|
|
7
|
+
reset(value?: number): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MockTotalCountReporter = void 0;
|
|
4
|
+
class MockTotalCountReporter {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.total = 1;
|
|
7
|
+
this.progress = 0;
|
|
8
|
+
}
|
|
9
|
+
setTotal(total) {
|
|
10
|
+
this.total = total;
|
|
11
|
+
this.reset();
|
|
12
|
+
}
|
|
13
|
+
increment(n) {
|
|
14
|
+
this.progress += n !== null && n !== void 0 ? n : 1;
|
|
15
|
+
}
|
|
16
|
+
reset(value) {
|
|
17
|
+
this.progress = value !== null && value !== void 0 ? value : 0;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.MockTotalCountReporter = MockTotalCountReporter;
|
|
21
|
+
//# sourceMappingURL=MockTotalCountReporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MockTotalCountReporter.js","sourceRoot":"","sources":["../../../src/reporter/totalCount/MockTotalCountReporter.ts"],"names":[],"mappings":";;;AAEA,MAAa,sBAAsB;IAAnC;QACU,UAAK,GAAG,CAAC,CAAC;QAEV,aAAQ,GAAG,CAAC,CAAC;IAcvB,CAAC;IAZC,QAAQ,CAAC,KAAa;QACpB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAED,SAAS,CAAC,CAAU;QAClB,IAAI,CAAC,QAAQ,IAAI,CAAC,aAAD,CAAC,cAAD,CAAC,GAAI,CAAC,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,KAAc;QAClB,IAAI,CAAC,QAAQ,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,CAAC,CAAC;IAC7B,CAAC;CACF;AAjBD,wDAiBC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Worker, WorkerStatus } from "./worker";
|
|
2
|
-
export declare type
|
|
2
|
+
export declare type WorkerStatusWithId = {
|
|
3
3
|
status: WorkerStatus;
|
|
4
4
|
} & {
|
|
5
5
|
id: string;
|
|
@@ -16,7 +16,7 @@ export declare class WorkerRepository {
|
|
|
16
16
|
static get Instance(): WorkerRepository;
|
|
17
17
|
registerWorker(queueName: string, workerClass: WorkerClass): WorkerRepository;
|
|
18
18
|
getWorkersByQueues(queueNames: string[]): Worker[];
|
|
19
|
-
getWorkerStatuses():
|
|
19
|
+
getWorkerStatuses(): WorkerStatusWithId[];
|
|
20
20
|
getCloseConnections(): Promise<void>[];
|
|
21
21
|
private get workers();
|
|
22
22
|
private get activeWorkers();
|
|
@@ -32,12 +32,17 @@ class WorkerRepository {
|
|
|
32
32
|
this._activeWorkers.push(worker);
|
|
33
33
|
return worker;
|
|
34
34
|
}
|
|
35
|
-
this.getLogger().warn("worker_repository.invalid_queue_name", {
|
|
35
|
+
this.getLogger().warn("worker_repository.invalid_queue_name", {
|
|
36
|
+
queueName,
|
|
37
|
+
});
|
|
36
38
|
return null;
|
|
37
39
|
}));
|
|
38
40
|
}
|
|
39
41
|
getWorkerStatuses() {
|
|
40
|
-
return this.activeWorkers.map((worker) => ({
|
|
42
|
+
return this.activeWorkers.map((worker) => ({
|
|
43
|
+
id: worker.id,
|
|
44
|
+
status: worker.status,
|
|
45
|
+
}));
|
|
41
46
|
}
|
|
42
47
|
getCloseConnections() {
|
|
43
48
|
return this.activeWorkers.map((worker) => worker.close());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workerRepository.js","sourceRoot":"","sources":["../../src/worker/workerRepository.ts"],"names":[],"mappings":";;;AACA,mCAA0C;AAC1C,4DAAyD;AASzD,MAAa,gBAAgB;IAS3B;QACE,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,qCAAiB,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC;IAC7D,CAAC;IAEM,MAAM,KAAK,QAAQ;QACxB,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,OAAO,IAAI,CAAC,SAAS,CAAC;SACvB;QACD,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAEM,cAAc,
|
|
1
|
+
{"version":3,"file":"workerRepository.js","sourceRoot":"","sources":["../../src/worker/workerRepository.ts"],"names":[],"mappings":";;;AACA,mCAA0C;AAC1C,4DAAyD;AASzD,MAAa,gBAAgB;IAS3B;QACE,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,qCAAiB,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC;IAC7D,CAAC;IAEM,MAAM,KAAK,QAAQ;QACxB,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,OAAO,IAAI,CAAC,SAAS,CAAC;SACvB;QACD,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAEM,cAAc,CACnB,SAAiB,EACjB,WAAwB;QAExB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;QAC1D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,kBAAkB,CAAC,UAAoB;QACrC,IAAI,IAAA,gBAAO,EAAC,IAAI,CAAC,OAAO,CAAC,EAAE;YACzB,IAAI,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;YACrE,OAAO,EAAE,CAAC;SACX;QAED,OAAO,IAAA,gBAAO,EACZ,UAAU,CAAC,GAAG,CAAC,CAAC,SAAiB,EAAE,EAAE;YACnC,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;gBAC3B,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC7C,oEAAoE;gBACpE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACjC,OAAO,MAAM,CAAC;aACf;YACD,IAAI,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,sCAAsC,EAAE;gBAC5D,SAAS;aACV,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED,iBAAiB;QACf,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YACzC,EAAE,EAAE,MAAM,CAAC,EAAE;YACb,MAAM,EAAE,MAAM,CAAC,MAAM;SACtB,CAAC,CAAC,CAAC;IACN,CAAC;IAEM,mBAAmB;QACxB,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,IAAY,OAAO;QACjB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAY,aAAa;QACvB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;CACF;AAvED,4CAuEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alanszp/queue",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.3.0",
|
|
4
4
|
"description": "Workers and queues",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "^15.12.3",
|
|
23
|
+
"class-validator": "^0.13.1",
|
|
23
24
|
"ts-node": "^10.0.0",
|
|
24
25
|
"tslint": "^6.1.3",
|
|
25
26
|
"typescript": "^4.3.4"
|
|
@@ -29,9 +30,10 @@
|
|
|
29
30
|
"@alanszp/core": "^9.2.2",
|
|
30
31
|
"@alanszp/logger": "^9.0.0",
|
|
31
32
|
"@alanszp/shared-context": "^9.0.0",
|
|
33
|
+
"@alanszp/validations": "^9.0.0",
|
|
32
34
|
"bullmq": "^2.1.2",
|
|
33
35
|
"ioredis": "^5.2.3",
|
|
34
36
|
"lodash": "^4.17.21"
|
|
35
37
|
},
|
|
36
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "01f4cf7780357778908e8d40007747d8aa580c70"
|
|
37
39
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ILogger } from "@alanszp/logger";
|
|
2
|
+
import { BaseModel } from "@alanszp/validations";
|
|
3
|
+
import { CreateAsyncJobInput } from "../inputs/CreateAsyncJobInput";
|
|
4
|
+
import { Queue } from "../../queue/queue";
|
|
5
|
+
import { Job } from "../../types";
|
|
6
|
+
|
|
7
|
+
export async function asyncJobCreationCommand<
|
|
8
|
+
QueueInputBody,
|
|
9
|
+
RealInput extends BaseModel & QueueInputBody,
|
|
10
|
+
AsyncInput extends CreateAsyncJobInput<RealInput>
|
|
11
|
+
>(
|
|
12
|
+
logger: ILogger,
|
|
13
|
+
queue: Queue<QueueInputBody>,
|
|
14
|
+
input: AsyncInput
|
|
15
|
+
): Promise<Job<QueueInputBody>> {
|
|
16
|
+
const child = logger.child({
|
|
17
|
+
input,
|
|
18
|
+
queueName: queue.getName(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
child.info("worker.async.create_job.starting");
|
|
22
|
+
await input.validate();
|
|
23
|
+
|
|
24
|
+
child.debug("worker.async.create_job.validated");
|
|
25
|
+
|
|
26
|
+
const job = await queue.publishJob(input.asyncInput, {
|
|
27
|
+
delay: input.getDelayInMs(),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
child.debug("worker.async.create_job.succeed", { jobId: job.id });
|
|
31
|
+
|
|
32
|
+
return job;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function immediateExecutionJobCreationCommand<
|
|
36
|
+
QueueInputBody,
|
|
37
|
+
RealInput extends QueueInputBody & BaseModel
|
|
38
|
+
>(
|
|
39
|
+
logger: ILogger,
|
|
40
|
+
queue: Queue<QueueInputBody>,
|
|
41
|
+
input: RealInput
|
|
42
|
+
): Promise<Job<QueueInputBody>> {
|
|
43
|
+
const child = logger.child({
|
|
44
|
+
input,
|
|
45
|
+
queueName: queue.getName(),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
child.info("worker.async.create_job.starting");
|
|
49
|
+
await input.validate();
|
|
50
|
+
|
|
51
|
+
child.debug("worker.async.create_job.validated");
|
|
52
|
+
|
|
53
|
+
const job = await queue.publishJob(input);
|
|
54
|
+
|
|
55
|
+
child.debug("worker.async.create_job.succeed", { jobId: job.id });
|
|
56
|
+
|
|
57
|
+
return job;
|
|
58
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ILogger } from "@alanszp/logger";
|
|
2
|
+
import { GetJobInput } from "../inputs/GetJobInput";
|
|
3
|
+
import { SearchJobsInput } from "../inputs/SearchJobsInput";
|
|
4
|
+
import { ListResult } from "@alanszp/core";
|
|
5
|
+
import { Queue } from "../../queue/queue";
|
|
6
|
+
import { Job } from "../../types";
|
|
7
|
+
|
|
8
|
+
export async function getJobStatus<QueueInputBody, ReturnValue>(
|
|
9
|
+
logger: ILogger,
|
|
10
|
+
queue: Queue<QueueInputBody, ReturnValue>,
|
|
11
|
+
input: GetJobInput
|
|
12
|
+
): Promise<Job<QueueInputBody, ReturnValue> | undefined> {
|
|
13
|
+
const child = logger.child({
|
|
14
|
+
input,
|
|
15
|
+
queueName: queue.getName(),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
child.info("worker.get_job.starting");
|
|
19
|
+
await input.validate();
|
|
20
|
+
|
|
21
|
+
child.debug("worker.get_job.validated");
|
|
22
|
+
|
|
23
|
+
const job = await queue.getJobOrFail(input.jobId);
|
|
24
|
+
|
|
25
|
+
child.info("worker.get_job.succeed", { jobId: job?.id ?? null });
|
|
26
|
+
|
|
27
|
+
return job;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function searchJobsCommand<QueueInputBody, ReturnValue>(
|
|
31
|
+
logger: ILogger,
|
|
32
|
+
queue: Queue<QueueInputBody, ReturnValue>,
|
|
33
|
+
input: SearchJobsInput
|
|
34
|
+
): Promise<ListResult<Job<QueueInputBody, ReturnValue>>> {
|
|
35
|
+
const child = logger.child({
|
|
36
|
+
input,
|
|
37
|
+
queueName: queue.getName(),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
child.info("worker.get_job.starting");
|
|
41
|
+
await input.validate();
|
|
42
|
+
|
|
43
|
+
child.debug("worker.get_job.validated");
|
|
44
|
+
|
|
45
|
+
const jobs = await queue.getJobsAndCountByStatus(
|
|
46
|
+
input.status,
|
|
47
|
+
input.page,
|
|
48
|
+
input.pageSize
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
child.info("worker.get_job.succeed", {
|
|
52
|
+
jobTotal: jobs.total,
|
|
53
|
+
jobInPage: jobs.elements.length,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return jobs;
|
|
57
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./inputs/CreateAsyncJobInput";
|
|
2
|
+
export * from "./inputs/GetJobInput";
|
|
3
|
+
export * from "./inputs/SearchJobsInput";
|
|
4
|
+
export * from "./commands/asyncCreationCommands";
|
|
5
|
+
export * from "./commands/getCommands";
|
|
6
|
+
export * from "./commands/workerHealthCommand";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { IsDateString, IsDefined, IsOptional } from "class-validator";
|
|
2
|
+
import { BaseModel } from "@alanszp/validations";
|
|
3
|
+
import { differenceInMilliseconds } from "date-fns";
|
|
4
|
+
|
|
5
|
+
export interface CreateAsyncJobQueryParams {
|
|
6
|
+
executeOn?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class CreateAsyncJobInput<
|
|
10
|
+
RealInput extends BaseModel
|
|
11
|
+
> extends BaseModel {
|
|
12
|
+
@IsDateString()
|
|
13
|
+
@IsOptional()
|
|
14
|
+
public executeOn?: string;
|
|
15
|
+
|
|
16
|
+
@IsDefined()
|
|
17
|
+
public asyncInput: RealInput;
|
|
18
|
+
|
|
19
|
+
constructor(asyncParams: CreateAsyncJobQueryParams, asyncInput: RealInput) {
|
|
20
|
+
super();
|
|
21
|
+
this.executeOn = asyncParams.executeOn;
|
|
22
|
+
this.asyncInput = asyncInput;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async validate(): Promise<void> {
|
|
26
|
+
await super.validate();
|
|
27
|
+
|
|
28
|
+
await this.asyncInput.validate();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getDelayInMs(): number | undefined {
|
|
32
|
+
if (!this.executeOn) return undefined;
|
|
33
|
+
const date = new Date(this.executeOn);
|
|
34
|
+
const delay = differenceInMilliseconds(date, new Date());
|
|
35
|
+
return delay > 0 ? delay : undefined;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IsDefined, IsString } from "class-validator";
|
|
2
|
+
import { BaseModel } from "@alanszp/validations";
|
|
3
|
+
|
|
4
|
+
export class GetJobInput extends BaseModel {
|
|
5
|
+
@IsDefined()
|
|
6
|
+
@IsString()
|
|
7
|
+
public jobId: string;
|
|
8
|
+
|
|
9
|
+
constructor(jobId: string) {
|
|
10
|
+
super();
|
|
11
|
+
this.jobId = jobId;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async validate(): Promise<void> {
|
|
15
|
+
await super.validate();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IsDefined,
|
|
3
|
+
IsArray,
|
|
4
|
+
IsEnum,
|
|
5
|
+
IsNumber,
|
|
6
|
+
Min,
|
|
7
|
+
Max,
|
|
8
|
+
} from "class-validator";
|
|
9
|
+
import { BaseModel } from "@alanszp/validations";
|
|
10
|
+
import { JobTypeEnum } from "../../types";
|
|
11
|
+
import { assignPaginableKeys } from "@alanszp/core";
|
|
12
|
+
|
|
13
|
+
export interface SearchJobInputProps {
|
|
14
|
+
status: JobTypeEnum[];
|
|
15
|
+
page?: string | number;
|
|
16
|
+
pageSize?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class SearchJobsInput extends BaseModel {
|
|
20
|
+
@IsDefined()
|
|
21
|
+
@IsArray()
|
|
22
|
+
@IsEnum(JobTypeEnum, { each: true })
|
|
23
|
+
public status: JobTypeEnum[];
|
|
24
|
+
|
|
25
|
+
@IsDefined()
|
|
26
|
+
@IsNumber()
|
|
27
|
+
@Min(1)
|
|
28
|
+
public page: number;
|
|
29
|
+
|
|
30
|
+
@IsDefined()
|
|
31
|
+
@IsNumber()
|
|
32
|
+
@Min(1)
|
|
33
|
+
@Max(100)
|
|
34
|
+
public pageSize: number;
|
|
35
|
+
|
|
36
|
+
constructor({ status, page, pageSize }: SearchJobInputProps) {
|
|
37
|
+
super();
|
|
38
|
+
this.status = status;
|
|
39
|
+
assignPaginableKeys(this, { page, pageSize });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async validate(): Promise<void> {
|
|
43
|
+
await super.validate();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Job } from "../../types";
|
|
2
|
+
import { ITotalCountReporter } from "./ITotalCountReporter";
|
|
3
|
+
|
|
4
|
+
export class JobTotalCountReporter<JobInstance extends Job>
|
|
5
|
+
implements ITotalCountReporter
|
|
6
|
+
{
|
|
7
|
+
private total = 1;
|
|
8
|
+
|
|
9
|
+
private current = 0;
|
|
10
|
+
|
|
11
|
+
private job: JobInstance;
|
|
12
|
+
|
|
13
|
+
constructor(job: JobInstance) {
|
|
14
|
+
this.job = job;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
setTotal(total: number): void {
|
|
18
|
+
this.total = total;
|
|
19
|
+
this.reset();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
increment(n?: number): void {
|
|
23
|
+
this.current += n ?? 1;
|
|
24
|
+
this.report();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
reset(value?: number): void {
|
|
28
|
+
this.current = value ?? 0;
|
|
29
|
+
this.report();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
report() {
|
|
33
|
+
this.job
|
|
34
|
+
.updateProgress({ total: this.total, current: this.current })
|
|
35
|
+
.catch(() => {});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ITotalCountReporter } from "./ITotalCountReporter";
|
|
2
|
+
|
|
3
|
+
export class MockTotalCountReporter implements ITotalCountReporter {
|
|
4
|
+
private total = 1;
|
|
5
|
+
|
|
6
|
+
private progress = 0;
|
|
7
|
+
|
|
8
|
+
setTotal(total: number): void {
|
|
9
|
+
this.total = total;
|
|
10
|
+
this.reset();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
increment(n?: number): void {
|
|
14
|
+
this.progress += n ?? 1;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
reset(value?: number): void {
|
|
18
|
+
this.progress = value ?? 0;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -3,7 +3,7 @@ import { compact, isEmpty } from "lodash";
|
|
|
3
3
|
import { ConnectionManager } from "../connectionManager";
|
|
4
4
|
import { Worker, WorkerStatus } from "./worker";
|
|
5
5
|
|
|
6
|
-
export type
|
|
6
|
+
export type WorkerStatusWithId = { status: WorkerStatus } & { id: string };
|
|
7
7
|
interface WorkerClass {
|
|
8
8
|
new (): Worker;
|
|
9
9
|
}
|
|
@@ -32,7 +32,10 @@ export class WorkerRepository {
|
|
|
32
32
|
return this._instance;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
public registerWorker(
|
|
35
|
+
public registerWorker(
|
|
36
|
+
queueName: string,
|
|
37
|
+
workerClass: WorkerClass
|
|
38
|
+
): WorkerRepository {
|
|
36
39
|
Object.assign(this.workers, { [queueName]: workerClass });
|
|
37
40
|
return this;
|
|
38
41
|
}
|
|
@@ -51,14 +54,19 @@ export class WorkerRepository {
|
|
|
51
54
|
this._activeWorkers.push(worker);
|
|
52
55
|
return worker;
|
|
53
56
|
}
|
|
54
|
-
this.getLogger().warn("worker_repository.invalid_queue_name", {
|
|
57
|
+
this.getLogger().warn("worker_repository.invalid_queue_name", {
|
|
58
|
+
queueName,
|
|
59
|
+
});
|
|
55
60
|
return null;
|
|
56
61
|
})
|
|
57
62
|
);
|
|
58
63
|
}
|
|
59
64
|
|
|
60
|
-
getWorkerStatuses():
|
|
61
|
-
return this.activeWorkers.map((worker) => ({
|
|
65
|
+
getWorkerStatuses(): WorkerStatusWithId[] {
|
|
66
|
+
return this.activeWorkers.map((worker) => ({
|
|
67
|
+
id: worker.id,
|
|
68
|
+
status: worker.status,
|
|
69
|
+
}));
|
|
62
70
|
}
|
|
63
71
|
|
|
64
72
|
public getCloseConnections(): Promise<void>[] {
|