@alanszp/queue 12.0.2 → 13.0.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/package.json +7 -10
- package/.gitignore +0 -3
- package/.npmignore +0 -3
- package/node_modules/@alanszp/core/.gitignore +0 -3
- package/node_modules/@alanszp/core/.npmignore +0 -3
- package/node_modules/@alanszp/core/LICENSE +0 -21
- package/node_modules/@alanszp/core/dist/app/appIdentifier.d.ts +0 -1
- package/node_modules/@alanszp/core/dist/app/appIdentifier.js +0 -10
- package/node_modules/@alanszp/core/dist/app/appIdentifier.js.map +0 -1
- package/node_modules/@alanszp/core/dist/app/index.d.ts +0 -1
- package/node_modules/@alanszp/core/dist/app/index.js +0 -18
- package/node_modules/@alanszp/core/dist/app/index.js.map +0 -1
- package/node_modules/@alanszp/core/dist/assignKey.d.ts +0 -2
- package/node_modules/@alanszp/core/dist/assignKey.js +0 -20
- package/node_modules/@alanszp/core/dist/assignKey.js.map +0 -1
- package/node_modules/@alanszp/core/dist/editable/index.d.ts +0 -2
- package/node_modules/@alanszp/core/dist/editable/index.js +0 -19
- package/node_modules/@alanszp/core/dist/editable/index.js.map +0 -1
- package/node_modules/@alanszp/core/dist/editable/keepOrUpdate.d.ts +0 -3
- package/node_modules/@alanszp/core/dist/editable/keepOrUpdate.js +0 -26
- package/node_modules/@alanszp/core/dist/editable/keepOrUpdate.js.map +0 -1
- package/node_modules/@alanszp/core/dist/editable/types.d.ts +0 -6
- package/node_modules/@alanszp/core/dist/editable/types.js +0 -3
- package/node_modules/@alanszp/core/dist/editable/types.js.map +0 -1
- package/node_modules/@alanszp/core/dist/index.d.ts +0 -4
- package/node_modules/@alanszp/core/dist/index.js +0 -21
- package/node_modules/@alanszp/core/dist/index.js.map +0 -1
- package/node_modules/@alanszp/core/dist/lists/ListResult.d.ts +0 -7
- package/node_modules/@alanszp/core/dist/lists/ListResult.js +0 -8
- package/node_modules/@alanszp/core/dist/lists/ListResult.js.map +0 -1
- package/node_modules/@alanszp/core/dist/lists/Orderable.d.ts +0 -11
- package/node_modules/@alanszp/core/dist/lists/Orderable.js +0 -13
- package/node_modules/@alanszp/core/dist/lists/Orderable.js.map +0 -1
- package/node_modules/@alanszp/core/dist/lists/Paginable.d.ts +0 -14
- package/node_modules/@alanszp/core/dist/lists/Paginable.js +0 -22
- package/node_modules/@alanszp/core/dist/lists/Paginable.js.map +0 -1
- package/node_modules/@alanszp/core/dist/lists/index.d.ts +0 -3
- package/node_modules/@alanszp/core/dist/lists/index.js +0 -20
- package/node_modules/@alanszp/core/dist/lists/index.js.map +0 -1
- package/node_modules/@alanszp/core/package.json +0 -25
- package/node_modules/@alanszp/core/tsconfig.json +0 -15
- package/node_modules/@types/node/LICENSE +0 -21
- package/node_modules/@types/node/README.md +0 -15
- package/node_modules/@types/node/assert/strict.d.ts +0 -8
- package/node_modules/@types/node/assert.d.ts +0 -996
- package/node_modules/@types/node/async_hooks.d.ts +0 -539
- package/node_modules/@types/node/buffer.d.ts +0 -2362
- package/node_modules/@types/node/child_process.d.ts +0 -1540
- package/node_modules/@types/node/cluster.d.ts +0 -432
- package/node_modules/@types/node/console.d.ts +0 -415
- package/node_modules/@types/node/constants.d.ts +0 -19
- package/node_modules/@types/node/crypto.d.ts +0 -4487
- package/node_modules/@types/node/dgram.d.ts +0 -596
- package/node_modules/@types/node/diagnostics_channel.d.ts +0 -545
- package/node_modules/@types/node/dns/promises.d.ts +0 -425
- package/node_modules/@types/node/dns.d.ts +0 -809
- package/node_modules/@types/node/dom-events.d.ts +0 -122
- package/node_modules/@types/node/domain.d.ts +0 -170
- package/node_modules/@types/node/events.d.ts +0 -879
- package/node_modules/@types/node/fs/promises.d.ts +0 -1239
- package/node_modules/@types/node/fs.d.ts +0 -4311
- package/node_modules/@types/node/globals.d.ts +0 -411
- package/node_modules/@types/node/globals.global.d.ts +0 -1
- package/node_modules/@types/node/http.d.ts +0 -1887
- package/node_modules/@types/node/http2.d.ts +0 -2382
- package/node_modules/@types/node/https.d.ts +0 -550
- package/node_modules/@types/node/index.d.ts +0 -88
- package/node_modules/@types/node/inspector.d.ts +0 -2747
- package/node_modules/@types/node/module.d.ts +0 -315
- package/node_modules/@types/node/net.d.ts +0 -949
- package/node_modules/@types/node/os.d.ts +0 -478
- package/node_modules/@types/node/package.json +0 -229
- package/node_modules/@types/node/path.d.ts +0 -191
- package/node_modules/@types/node/perf_hooks.d.ts +0 -645
- package/node_modules/@types/node/process.d.ts +0 -1561
- package/node_modules/@types/node/punycode.d.ts +0 -117
- package/node_modules/@types/node/querystring.d.ts +0 -141
- package/node_modules/@types/node/readline/promises.d.ts +0 -150
- package/node_modules/@types/node/readline.d.ts +0 -539
- package/node_modules/@types/node/repl.d.ts +0 -430
- package/node_modules/@types/node/stream/consumers.d.ts +0 -12
- package/node_modules/@types/node/stream/promises.d.ts +0 -83
- package/node_modules/@types/node/stream/web.d.ts +0 -366
- package/node_modules/@types/node/stream.d.ts +0 -1701
- package/node_modules/@types/node/string_decoder.d.ts +0 -67
- package/node_modules/@types/node/test.d.ts +0 -1465
- package/node_modules/@types/node/timers/promises.d.ts +0 -93
- package/node_modules/@types/node/timers.d.ts +0 -240
- package/node_modules/@types/node/tls.d.ts +0 -1210
- package/node_modules/@types/node/trace_events.d.ts +0 -182
- package/node_modules/@types/node/ts4.8/assert/strict.d.ts +0 -8
- package/node_modules/@types/node/ts4.8/assert.d.ts +0 -996
- package/node_modules/@types/node/ts4.8/async_hooks.d.ts +0 -539
- package/node_modules/@types/node/ts4.8/buffer.d.ts +0 -2362
- package/node_modules/@types/node/ts4.8/child_process.d.ts +0 -1540
- package/node_modules/@types/node/ts4.8/cluster.d.ts +0 -432
- package/node_modules/@types/node/ts4.8/console.d.ts +0 -415
- package/node_modules/@types/node/ts4.8/constants.d.ts +0 -19
- package/node_modules/@types/node/ts4.8/crypto.d.ts +0 -4487
- package/node_modules/@types/node/ts4.8/dgram.d.ts +0 -596
- package/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +0 -545
- package/node_modules/@types/node/ts4.8/dns/promises.d.ts +0 -425
- package/node_modules/@types/node/ts4.8/dns.d.ts +0 -809
- package/node_modules/@types/node/ts4.8/dom-events.d.ts +0 -122
- package/node_modules/@types/node/ts4.8/domain.d.ts +0 -170
- package/node_modules/@types/node/ts4.8/events.d.ts +0 -879
- package/node_modules/@types/node/ts4.8/fs/promises.d.ts +0 -1239
- package/node_modules/@types/node/ts4.8/fs.d.ts +0 -4311
- package/node_modules/@types/node/ts4.8/globals.d.ts +0 -411
- package/node_modules/@types/node/ts4.8/globals.global.d.ts +0 -1
- package/node_modules/@types/node/ts4.8/http.d.ts +0 -1887
- package/node_modules/@types/node/ts4.8/http2.d.ts +0 -2382
- package/node_modules/@types/node/ts4.8/https.d.ts +0 -550
- package/node_modules/@types/node/ts4.8/index.d.ts +0 -88
- package/node_modules/@types/node/ts4.8/inspector.d.ts +0 -2747
- package/node_modules/@types/node/ts4.8/module.d.ts +0 -315
- package/node_modules/@types/node/ts4.8/net.d.ts +0 -949
- package/node_modules/@types/node/ts4.8/os.d.ts +0 -478
- package/node_modules/@types/node/ts4.8/path.d.ts +0 -191
- package/node_modules/@types/node/ts4.8/perf_hooks.d.ts +0 -645
- package/node_modules/@types/node/ts4.8/process.d.ts +0 -1561
- package/node_modules/@types/node/ts4.8/punycode.d.ts +0 -117
- package/node_modules/@types/node/ts4.8/querystring.d.ts +0 -141
- package/node_modules/@types/node/ts4.8/readline/promises.d.ts +0 -150
- package/node_modules/@types/node/ts4.8/readline.d.ts +0 -539
- package/node_modules/@types/node/ts4.8/repl.d.ts +0 -430
- package/node_modules/@types/node/ts4.8/stream/consumers.d.ts +0 -12
- package/node_modules/@types/node/ts4.8/stream/promises.d.ts +0 -83
- package/node_modules/@types/node/ts4.8/stream/web.d.ts +0 -366
- package/node_modules/@types/node/ts4.8/stream.d.ts +0 -1701
- package/node_modules/@types/node/ts4.8/string_decoder.d.ts +0 -67
- package/node_modules/@types/node/ts4.8/test.d.ts +0 -1465
- package/node_modules/@types/node/ts4.8/timers/promises.d.ts +0 -93
- package/node_modules/@types/node/ts4.8/timers.d.ts +0 -240
- package/node_modules/@types/node/ts4.8/tls.d.ts +0 -1210
- package/node_modules/@types/node/ts4.8/trace_events.d.ts +0 -182
- package/node_modules/@types/node/ts4.8/tty.d.ts +0 -208
- package/node_modules/@types/node/ts4.8/url.d.ts +0 -927
- package/node_modules/@types/node/ts4.8/util.d.ts +0 -2183
- package/node_modules/@types/node/ts4.8/v8.d.ts +0 -764
- package/node_modules/@types/node/ts4.8/vm.d.ts +0 -903
- package/node_modules/@types/node/ts4.8/wasi.d.ts +0 -179
- package/node_modules/@types/node/ts4.8/worker_threads.d.ts +0 -691
- package/node_modules/@types/node/ts4.8/zlib.d.ts +0 -517
- package/node_modules/@types/node/tty.d.ts +0 -208
- package/node_modules/@types/node/url.d.ts +0 -927
- package/node_modules/@types/node/util.d.ts +0 -2183
- package/node_modules/@types/node/v8.d.ts +0 -764
- package/node_modules/@types/node/vm.d.ts +0 -903
- package/node_modules/@types/node/wasi.d.ts +0 -179
- package/node_modules/@types/node/worker_threads.d.ts +0 -691
- package/node_modules/@types/node/zlib.d.ts +0 -517
- package/src/connectionManager.ts +0 -68
- package/src/errors/JobCannotBePromotedError.ts +0 -25
- package/src/errors/JobNotFoundError.ts +0 -20
- package/src/index.ts +0 -9
- package/src/jobsManagement/commands/asyncCreationCommands.ts +0 -58
- package/src/jobsManagement/commands/getCommands.ts +0 -57
- package/src/jobsManagement/commands/workerHealthCommand.ts +0 -10
- package/src/jobsManagement/index.ts +0 -6
- package/src/jobsManagement/inputs/CreateAsyncJobInput.ts +0 -36
- package/src/jobsManagement/inputs/GetJobInput.ts +0 -17
- package/src/jobsManagement/inputs/SearchJobsInput.ts +0 -45
- package/src/queue/createQueue.ts +0 -22
- package/src/queue/queue.ts +0 -195
- package/src/queue/queueRepository.ts +0 -27
- package/src/reporter/totalCount/ITotalCountReporter.ts +0 -5
- package/src/reporter/totalCount/JobTotalCountReporter.ts +0 -37
- package/src/reporter/totalCount/MockTotalCountReporter.ts +0 -20
- package/src/runner.ts +0 -16
- package/src/shutdownQueue.ts +0 -12
- package/src/types.ts +0 -38
- package/src/worker/worker.ts +0 -187
- package/src/worker/workerRepository.ts +0 -83
- package/src/wrappers/withContext.ts +0 -29
|
@@ -1,57 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
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";
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { IsDateString, IsDefined, IsOptional } from "class-validator";
|
|
2
|
-
import { BaseModel } from "@alanszp/validations";
|
|
3
|
-
|
|
4
|
-
export interface CreateAsyncJobQueryParams {
|
|
5
|
-
executeOn?: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export class CreateAsyncJobInput<
|
|
9
|
-
RealInput extends BaseModel
|
|
10
|
-
> extends BaseModel {
|
|
11
|
-
@IsDateString()
|
|
12
|
-
@IsOptional()
|
|
13
|
-
public executeOn?: string;
|
|
14
|
-
|
|
15
|
-
@IsDefined()
|
|
16
|
-
public asyncInput: RealInput;
|
|
17
|
-
|
|
18
|
-
constructor(asyncParams: CreateAsyncJobQueryParams, asyncInput: RealInput) {
|
|
19
|
-
super();
|
|
20
|
-
this.executeOn = asyncParams.executeOn;
|
|
21
|
-
this.asyncInput = asyncInput;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async validate(): Promise<void> {
|
|
25
|
-
await super.validate();
|
|
26
|
-
|
|
27
|
-
await this.asyncInput.validate();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
getDelayInMs(): number | undefined {
|
|
31
|
-
if (!this.executeOn) return undefined;
|
|
32
|
-
const date = new Date(this.executeOn);
|
|
33
|
-
const delay = date.getTime() - new Date().getTime();
|
|
34
|
-
return delay > 0 ? delay : undefined;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
}
|
package/src/queue/createQueue.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Queue } from "./queue";
|
|
2
|
-
import { QueueRepository } from "./queueRepository";
|
|
3
|
-
import { ConnectionManager } from "../connectionManager";
|
|
4
|
-
import { JobData, QueueOptions } from "../types";
|
|
5
|
-
import { SharedContext } from "@alanszp/shared-context";
|
|
6
|
-
|
|
7
|
-
export function createQueue<Data = JobData>(
|
|
8
|
-
name: string,
|
|
9
|
-
getContext: () => SharedContext,
|
|
10
|
-
queueOptions?: QueueOptions
|
|
11
|
-
): Queue<Data> {
|
|
12
|
-
const connection = ConnectionManager.getInstance().getConnection();
|
|
13
|
-
const queue = new Queue<Data>(
|
|
14
|
-
connection,
|
|
15
|
-
name,
|
|
16
|
-
ConnectionManager.getInstance().getServiceName(),
|
|
17
|
-
getContext,
|
|
18
|
-
queueOptions
|
|
19
|
-
);
|
|
20
|
-
QueueRepository.Instance.registerQueue(queue);
|
|
21
|
-
return queue;
|
|
22
|
-
}
|
package/src/queue/queue.ts
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import { merge, repeat } from "lodash";
|
|
2
|
-
import { Job, JobsOptions, RepeatOptions } from "bullmq";
|
|
3
|
-
import { ListResult } from "@alanszp/core";
|
|
4
|
-
import { SharedContext } from "@alanszp/shared-context";
|
|
5
|
-
import {
|
|
6
|
-
ConnectionOptions,
|
|
7
|
-
JobData,
|
|
8
|
-
JobReturnValue,
|
|
9
|
-
JobStateEnum,
|
|
10
|
-
JobTypeEnum,
|
|
11
|
-
QueueOptions,
|
|
12
|
-
RawQueue,
|
|
13
|
-
} from "../types";
|
|
14
|
-
import { JobNotFoundError } from "../errors/JobNotFoundError";
|
|
15
|
-
import { JobCannotBePromotedError } from "../errors/JobCannotBePromotedError";
|
|
16
|
-
import { ResultTypes } from "ioredis/built/utils/RedisCommander";
|
|
17
|
-
|
|
18
|
-
const BULL_PREFIX = "b";
|
|
19
|
-
|
|
20
|
-
const DEFAULT_COMPLETED_JOB_MAX_AGE_IN_SECONDS = 60 * 60 * 24 * 30;
|
|
21
|
-
const DEFAULT_COMPLETED_JOB_MAX_COUNT = 500;
|
|
22
|
-
const DEFAULT_FAILED_JOB_MAX_COUNT = 1000;
|
|
23
|
-
|
|
24
|
-
export class Queue<Data = JobData, ReturnValue = JobReturnValue> {
|
|
25
|
-
private _queue: RawQueue;
|
|
26
|
-
|
|
27
|
-
private name: string;
|
|
28
|
-
|
|
29
|
-
private getSharedContext: () => SharedContext;
|
|
30
|
-
|
|
31
|
-
constructor(
|
|
32
|
-
connection: ConnectionOptions,
|
|
33
|
-
name: string,
|
|
34
|
-
prefix: string,
|
|
35
|
-
getSharedContext: () => SharedContext,
|
|
36
|
-
queueOptions?: QueueOptions
|
|
37
|
-
) {
|
|
38
|
-
this.name = name;
|
|
39
|
-
|
|
40
|
-
this.getSharedContext = getSharedContext;
|
|
41
|
-
|
|
42
|
-
this._queue = new RawQueue<Data>(name, {
|
|
43
|
-
...merge(
|
|
44
|
-
{
|
|
45
|
-
defaultJobOptions: {
|
|
46
|
-
removeOnComplete: {
|
|
47
|
-
age: DEFAULT_COMPLETED_JOB_MAX_AGE_IN_SECONDS,
|
|
48
|
-
count: DEFAULT_COMPLETED_JOB_MAX_COUNT,
|
|
49
|
-
},
|
|
50
|
-
removeOnFail: {
|
|
51
|
-
count: DEFAULT_FAILED_JOB_MAX_COUNT,
|
|
52
|
-
},
|
|
53
|
-
attempts: 3,
|
|
54
|
-
backoff: {
|
|
55
|
-
type: "exponential",
|
|
56
|
-
delay: 3000,
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
connection,
|
|
60
|
-
},
|
|
61
|
-
queueOptions || {}
|
|
62
|
-
),
|
|
63
|
-
...{ prefix: `{${prefix}}:${BULL_PREFIX}` },
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
public getName(): string {
|
|
68
|
-
return this.name;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async publishJob(
|
|
72
|
-
job: Data,
|
|
73
|
-
opts?: JobsOptions
|
|
74
|
-
): Promise<Job<Data, ReturnValue>> {
|
|
75
|
-
const context = this.getSharedContext();
|
|
76
|
-
const lid = context.getLifecycleId();
|
|
77
|
-
const lch = context.getLifecycleChain();
|
|
78
|
-
return this.queue.add(this.name, { ...job, lid, lch }, opts);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async publishRepeatableJob(
|
|
82
|
-
job: Data,
|
|
83
|
-
repeatOptions: RepeatOptions,
|
|
84
|
-
jobId: string
|
|
85
|
-
): Promise<Job<Data, ReturnValue>> {
|
|
86
|
-
return this.queue.add(this.name, job, { ...repeatOptions, jobId });
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async removeRepeatableJobByKey(repeatJobKey: string): Promise<boolean> {
|
|
90
|
-
return this.queue.removeRepeatableByKey(repeatJobKey);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async removeRepeatableJobByConfig(
|
|
94
|
-
repeatOptions: RepeatOptions,
|
|
95
|
-
jobId: string
|
|
96
|
-
): Promise<boolean> {
|
|
97
|
-
return this.queue.removeRepeatable(this.name, repeatOptions, jobId);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async publishBulkJob(jobDatas: Data[]): Promise<Job<Data, ReturnValue>[]> {
|
|
101
|
-
const jobs = jobDatas.map((data) => ({ name: this.name, data }));
|
|
102
|
-
return this.queue.addBulk(jobs);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async publishBulkJobWithOptions(
|
|
106
|
-
jobDefinitions: { jobData: Data; opts: JobsOptions }[]
|
|
107
|
-
): Promise<Job<Data, ReturnValue>[]> {
|
|
108
|
-
const jobs = jobDefinitions.map(({ jobData: data, opts }) => ({
|
|
109
|
-
name: this.name,
|
|
110
|
-
data,
|
|
111
|
-
opts,
|
|
112
|
-
}));
|
|
113
|
-
return this.queue.addBulk(jobs);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
private pageToStartEnd(pageNumber: number, pageSize: number) {
|
|
117
|
-
return {
|
|
118
|
-
start: (pageNumber - 1) * pageSize,
|
|
119
|
-
end: pageNumber * pageSize - 1,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
public async getJobsAndCountByStatus(
|
|
124
|
-
statuses: JobTypeEnum[],
|
|
125
|
-
page: number = 1,
|
|
126
|
-
pageSize: number = 50,
|
|
127
|
-
ascending: boolean = false
|
|
128
|
-
): Promise<ListResult<Job<Data, ReturnValue>>> {
|
|
129
|
-
const { start, end } = this.pageToStartEnd(page, pageSize);
|
|
130
|
-
const [total, elements] = await Promise.all([
|
|
131
|
-
this.queue.getJobCountByTypes(...statuses),
|
|
132
|
-
this.queue.getJobs(statuses, start, end, ascending),
|
|
133
|
-
]);
|
|
134
|
-
|
|
135
|
-
return {
|
|
136
|
-
total,
|
|
137
|
-
elements,
|
|
138
|
-
page,
|
|
139
|
-
pageSize,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
public async getJobCountByStatus(
|
|
144
|
-
statuses: JobTypeEnum[],
|
|
145
|
-
page: number = 1,
|
|
146
|
-
pageSize: number = 50
|
|
147
|
-
): Promise<number> {
|
|
148
|
-
return this.queue.getJobCountByTypes(...statuses);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
public async getJobsByStatus(
|
|
152
|
-
statuses: JobTypeEnum[],
|
|
153
|
-
page: number = 1,
|
|
154
|
-
pageSize: number = 50,
|
|
155
|
-
ascending: boolean = false
|
|
156
|
-
): Promise<Job<Data, ReturnValue>[]> {
|
|
157
|
-
const { start, end } = this.pageToStartEnd(page, pageSize);
|
|
158
|
-
return this.queue.getJobs(statuses, start, end, ascending);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
public async deleteJob(jobId: string) {
|
|
162
|
-
this.queue.remove(jobId);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
public async getJob(
|
|
166
|
-
jobId: string
|
|
167
|
-
): Promise<Job<Data, ReturnValue> | undefined> {
|
|
168
|
-
return this.queue.getJob(jobId);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
public async getJobOrFail(jobId: string): Promise<Job<Data, ReturnValue>> {
|
|
172
|
-
const job = await this.queue.getJob(jobId);
|
|
173
|
-
if (!job) throw new JobNotFoundError(jobId);
|
|
174
|
-
return job;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
public async changeDelayToJob(jobId: string, delayMs: number) {
|
|
178
|
-
const job = await this.getJobOrFail(jobId);
|
|
179
|
-
|
|
180
|
-
const state = await job.getState();
|
|
181
|
-
if (state !== JobStateEnum.DELAYED) {
|
|
182
|
-
throw new JobCannotBePromotedError(jobId, state);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
job.changeDelay(delayMs);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
async close(): Promise<void> {
|
|
189
|
-
await this.queue.close();
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
private get queue(): RawQueue<Data, ReturnValue> {
|
|
193
|
-
return this._queue;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Queue } from "./queue";
|
|
2
|
-
|
|
3
|
-
export class QueueRepository {
|
|
4
|
-
private _queues: Queue[];
|
|
5
|
-
|
|
6
|
-
private static _instance: QueueRepository;
|
|
7
|
-
|
|
8
|
-
private constructor() {
|
|
9
|
-
this._queues = [];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public static get Instance(): QueueRepository {
|
|
13
|
-
if (this._instance) {
|
|
14
|
-
return this._instance;
|
|
15
|
-
}
|
|
16
|
-
this._instance = new this();
|
|
17
|
-
return this._instance;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public registerQueue(queue: Queue) {
|
|
21
|
-
this._queues.push(queue);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public getCloseConnections(): Promise<void>[] {
|
|
25
|
-
return this._queues.map((q) => q.close());
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
}
|
package/src/runner.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { ConnectionManager } from "./connectionManager";
|
|
3
|
-
import { Worker } from "./worker/worker";
|
|
4
|
-
import { WorkerRepository } from "./worker/workerRepository";
|
|
5
|
-
|
|
6
|
-
export async function runWorkers(queueNames: string): Promise<void> {
|
|
7
|
-
if (queueNames.length === 0) {
|
|
8
|
-
ConnectionManager.getInstance().getLogger().warn("worker.env.workers_queues_empty");
|
|
9
|
-
return Promise.resolve();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const queues: string[] = queueNames.replace(/\s/g, "").split(",");
|
|
13
|
-
const workers = WorkerRepository.Instance.getWorkersByQueues(queues);
|
|
14
|
-
|
|
15
|
-
await Promise.all(workers.map((worker: Worker) => worker.run()));
|
|
16
|
-
}
|
package/src/shutdownQueue.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { QueueRepository } from "./queue/queueRepository";
|
|
2
|
-
import { ConnectionManager } from "./connectionManager";
|
|
3
|
-
import { WorkerRepository } from "./worker/workerRepository";
|
|
4
|
-
|
|
5
|
-
export async function shutdownQueue(): Promise<void> {
|
|
6
|
-
await Promise.all([
|
|
7
|
-
...WorkerRepository.Instance.getCloseConnections(),
|
|
8
|
-
...QueueRepository.Instance.getCloseConnections(),
|
|
9
|
-
]);
|
|
10
|
-
|
|
11
|
-
ConnectionManager.getInstance().close();
|
|
12
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// decoupling from bullmq
|
|
2
|
-
export {
|
|
3
|
-
ConnectionOptions,
|
|
4
|
-
RedisOptions,
|
|
5
|
-
Job,
|
|
6
|
-
Worker as RawWorker,
|
|
7
|
-
WorkerOptions,
|
|
8
|
-
Queue as RawQueue,
|
|
9
|
-
QueueOptions,
|
|
10
|
-
JobState,
|
|
11
|
-
JobType,
|
|
12
|
-
JobsOptions,
|
|
13
|
-
} from "bullmq";
|
|
14
|
-
|
|
15
|
-
export type JobData = unknown;
|
|
16
|
-
|
|
17
|
-
export type JobReturnValue = unknown;
|
|
18
|
-
|
|
19
|
-
export enum JobStateEnum {
|
|
20
|
-
ACTIVE = "active",
|
|
21
|
-
DELAYED = "delayed",
|
|
22
|
-
WAITING = "waiting",
|
|
23
|
-
COMPLETED = "completed",
|
|
24
|
-
FAILED = "failed",
|
|
25
|
-
WAITING_CHILDREN = "waiting-children",
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export enum JobTypeEnum {
|
|
29
|
-
ACTIVE = "active",
|
|
30
|
-
DELAYED = "delayed",
|
|
31
|
-
WAITING = "waiting",
|
|
32
|
-
COMPLETED = "completed",
|
|
33
|
-
FAILED = "failed",
|
|
34
|
-
WAITING_CHILDREN = "waiting-children",
|
|
35
|
-
PAUSED = "paused",
|
|
36
|
-
REPEAT = "repeat",
|
|
37
|
-
WAIT = "wait",
|
|
38
|
-
}
|