@midwayjs/bull 3.0.4 → 3.0.5

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/README.md CHANGED
@@ -1,126 +1,9 @@
1
1
  # @midwayjs/bull
2
2
 
3
- ## 简介
3
+ this is a sub package for midway.
4
4
 
5
- midwayjs/bull 是为了能解决任务系列的模块,例如分布式定时任务、延迟任务调度。例如订单2小时后失效、每日定时的数据处理等工作。
5
+ Document: [https://midwayjs.org](https://midwayjs.org)
6
6
 
7
- ## 安装方法
7
+ ## License
8
8
 
9
- ```bash
10
- tnpm install @midwayjs/bull -S
11
- ```
12
-
13
- ## 使用方法
14
-
15
- 在Configuration.ts 导入组件
16
-
17
- ```typescript
18
-
19
- import * as bull from '@midwayjs/bull';
20
-
21
- @Configuration({
22
- imports: [bull],
23
- importConfigs: [
24
- join(__dirname, 'config')
25
- ]
26
- })
27
- export class AutoConfiguration{
28
- }
29
- ```
30
-
31
- 配置:
32
-
33
- 在 config.default.ts 文件中配置对应的模块信息:
34
-
35
- ```typescript
36
- export const bull = {
37
- defaultQueueOptions: {
38
- redis: `redis://127.0.0.1:6379`,
39
- prefix: 'midway-task',
40
- }
41
- defaultJobOptions: {
42
- repeat: {
43
- tz: "Asia/Shanghai"
44
- }
45
- }
46
- }
47
- ```
48
-
49
- ## 业务代码编写方式
50
-
51
- 定义一个任务处理器
52
-
53
- ```typescript
54
- @Processor('test')
55
- export class UserServiceProcessor {
56
- @Inject()
57
- helloService: HelloService;
58
-
59
- async execute(data: any) {
60
- console.log(this.helloService.getName());
61
-
62
- // console data
63
- console.log(data);
64
- }
65
- }
66
- ```
67
-
68
- 在需要的地方手动执行
69
-
70
- ```typescript
71
- import * as bull from '@midwayjs/bull';
72
-
73
- @Configuration({
74
- imports: [bull],
75
- importConfigs: [
76
- join(__dirname, 'config')
77
- ]
78
- })
79
- export class AutoConfiguration {
80
- @Inject()
81
- bullFramework: bull.BullFramework;
82
-
83
- async onServerReady() {
84
- bullFramework.getQueue('test').runJob({
85
- name: 'test'
86
- });
87
- }
88
- }
89
- ```
90
-
91
-
92
- 定时执行任务:
93
-
94
- ```typescript
95
- @Processor('test', {
96
- repeat: {
97
- cron: '0 0 0 * * *'
98
- }
99
- })
100
- export class UserServiceProcessor {
101
- @Inject()
102
- helloService: HelloService;
103
-
104
- async execute(data: any) {
105
- console.log(this.helloService.getName());
106
-
107
- // console data
108
- console.log(data);
109
- }
110
- }
111
- ```
112
-
113
- ## 其他
114
-
115
- 关于task任务的配置:
116
- ```
117
- * * * * * *
118
- ┬ ┬ ┬ ┬ ┬ ┬
119
- │ │ │ │ │ |
120
- │ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun)
121
- │ │ │ │ └───── month (1 - 12)
122
- │ │ │ └────────── day of month (1 - 31)
123
- │ │ └─────────────── hour (0 - 23)
124
- │ └──────────────────── minute (0 - 59)
125
- └───────────────────────── second (0 - 59, optional)
126
- ```
9
+ [MIT]((http://github.com/midwayjs/midway/blob/master/LICENSE))
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.midwayLogger = exports.bull = void 0;
4
4
  exports.bull = {
5
5
  defaultQueueOptions: {
6
- prefix: '${midway-bull}',
6
+ prefix: '{midway-bull}',
7
7
  },
8
8
  defaultJobOptions: {
9
9
  removeOnSuccess: true,
@@ -38,7 +38,7 @@ __decorate([
38
38
  ], BullConfiguration.prototype, "init", null);
39
39
  BullConfiguration = __decorate([
40
40
  (0, decorator_1.Configuration)({
41
- namespace: 'task',
41
+ namespace: 'bull',
42
42
  importConfigs: [
43
43
  {
44
44
  default: DefaultConfig,
package/dist/decorator.js CHANGED
@@ -26,44 +26,4 @@ function InjectQueue(queueName) {
26
26
  });
27
27
  }
28
28
  exports.InjectQueue = InjectQueue;
29
- //
30
- // export function Queue(queueOptions?: QueueOptions): ClassDecorator;
31
- // export function Queue(
32
- // queueName?: string,
33
- // queueOptions?: QueueOptions
34
- // ): ClassDecorator;
35
- // export function Queue(
36
- // queueName?: string,
37
- // concurrency?: number,
38
- // queueOptions?: QueueOptions
39
- // ): ClassDecorator;
40
- // export function Queue(
41
- // queueName?: any,
42
- // concurrency?: any,
43
- // queueOptions?: QueueOptions
44
- // ): ClassDecorator {
45
- // return function (target) {
46
- // if (typeof queueName !== 'string') {
47
- // queueOptions = queueName;
48
- // queueName = `${target.name}:execute`;
49
- // concurrency = 1;
50
- // }
51
- // if (typeof concurrency !== 'number') {
52
- // queueOptions = concurrency;
53
- // concurrency = 1;
54
- // }
55
- // saveModule(BULL_QUEUE_KEY, target);
56
- // saveClassMetadata(
57
- // BULL_QUEUE_KEY,
58
- // {
59
- // queueName,
60
- // queueOptions,
61
- // concurrency,
62
- // },
63
- // target
64
- // );
65
- // Provide()(target);
66
- // Scope(ScopeEnum.Singleton)(target);
67
- // };
68
- // }
69
29
  //# sourceMappingURL=decorator.js.map
@@ -20,6 +20,7 @@ export declare class BullFramework extends BaseFramework<Application, Context, a
20
20
  createQueue(name: string, queueOptions?: QueueOptions): BullQueue;
21
21
  getQueue(name: string): BullQueue;
22
22
  ensureQueue(name: string): BullQueue;
23
+ getQueueList(): BullQueue[];
23
24
  addProcessor(processor: new (...args: any[]) => IProcessor, queueName: string | BullQueue, concurrency?: number): Promise<void>;
24
25
  runJob(queueName: string, jobData: any, options?: JobOptions): Promise<void>;
25
26
  getJob(queueName: string, jobName: string): Promise<Job>;
package/dist/framework.js CHANGED
@@ -79,6 +79,9 @@ let BullFramework = class BullFramework extends core_1.BaseFramework {
79
79
  }
80
80
  return this.queueMap.get(name);
81
81
  }
82
+ getQueueList() {
83
+ return Array.from(this.queueMap.values());
84
+ }
82
85
  async addProcessor(processor, queueName, concurrency) {
83
86
  const queue = typeof queueName === 'string' ? this.queueMap.get(queueName) : queueName;
84
87
  queue.process(concurrency !== null && concurrency !== void 0 ? concurrency : this.bullDefaultConcurrency, async (job) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/bull",
3
- "version": "3.0.4",
3
+ "version": "3.0.5",
4
4
  "description": "midway component for bull",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",