@tsed/agenda 7.73.1 → 7.73.3
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 +6 -6
- package/jest.config.js +0 -15
- package/lib/cjs/AgendaModule.js.map +0 -1
- package/lib/cjs/constants/constants.js.map +0 -1
- package/lib/cjs/decorators/agenda.js.map +0 -1
- package/lib/cjs/decorators/define.js.map +0 -1
- package/lib/cjs/decorators/every.js.map +0 -1
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/interfaces/AgendaStore.js.map +0 -1
- package/lib/cjs/interfaces/interfaces.js.map +0 -1
- package/lib/cjs/services/AgendaFactory.js.map +0 -1
- package/lib/esm/AgendaModule.js.map +0 -1
- package/lib/esm/constants/constants.js.map +0 -1
- package/lib/esm/decorators/agenda.js.map +0 -1
- package/lib/esm/decorators/define.js.map +0 -1
- package/lib/esm/decorators/every.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/interfaces/AgendaStore.js.map +0 -1
- package/lib/esm/interfaces/interfaces.js.map +0 -1
- package/lib/esm/services/AgendaFactory.js.map +0 -1
- package/lib/tsconfig.esm.tsbuildinfo +0 -1
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/src/AgendaModule.spec.ts +0 -220
- package/src/AgendaModule.ts +0 -150
- package/src/constants/constants.ts +0 -1
- package/src/decorators/agenda.spec.ts +0 -21
- package/src/decorators/agenda.ts +0 -16
- package/src/decorators/define.spec.ts +0 -48
- package/src/decorators/define.ts +0 -14
- package/src/decorators/every.spec.ts +0 -36
- package/src/decorators/every.ts +0 -14
- package/src/index.ts +0 -11
- package/src/interfaces/AgendaStore.ts +0 -13
- package/src/interfaces/interfaces.ts +0 -16
- package/src/services/AgendaFactory.ts +0 -15
- package/tsconfig.esm.json +0 -39
- package/tsconfig.json +0 -39
package/src/AgendaModule.spec.ts
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import {PlatformTest} from "@tsed/common";
|
|
2
|
-
import {Inject} from "@tsed/di";
|
|
3
|
-
import {Job} from "agenda";
|
|
4
|
-
import {AgendaModule} from "./AgendaModule.js";
|
|
5
|
-
import {Agenda} from "./decorators/agenda.js";
|
|
6
|
-
import {Define} from "./decorators/define.js";
|
|
7
|
-
import {Every} from "./decorators/every.js";
|
|
8
|
-
|
|
9
|
-
jest.mock("agenda", () => {
|
|
10
|
-
return {
|
|
11
|
-
Agenda: class {
|
|
12
|
-
close = jest.fn();
|
|
13
|
-
stop = jest.fn();
|
|
14
|
-
drain = jest.fn();
|
|
15
|
-
define = jest.fn();
|
|
16
|
-
every = jest.fn();
|
|
17
|
-
schedule = jest.fn();
|
|
18
|
-
now = jest.fn();
|
|
19
|
-
create = jest.fn().mockReturnValue({
|
|
20
|
-
repeatEvery: jest.fn().mockReturnThis(),
|
|
21
|
-
save: jest.fn()
|
|
22
|
-
});
|
|
23
|
-
start = jest.fn();
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
@Agenda({namespace: "test-nsp"})
|
|
29
|
-
class CustomCampaign {
|
|
30
|
-
@Inject()
|
|
31
|
-
agenda: AgendaModule;
|
|
32
|
-
|
|
33
|
-
job: Job;
|
|
34
|
-
|
|
35
|
-
$beforeAgendaStart() {
|
|
36
|
-
this.job = this.agenda.create("customName2", {
|
|
37
|
-
locale: "fr-FR"
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
$afterAgendaStart() {
|
|
42
|
-
return this.job.repeatEvery("1 week").save();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@Every("60 seconds")
|
|
46
|
-
test(job: Job) {
|
|
47
|
-
// test
|
|
48
|
-
return "hello " + job.attrs.name;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
@Define({name: "customName"})
|
|
52
|
-
test2(job: Job) {
|
|
53
|
-
// test
|
|
54
|
-
return "hello " + job.attrs.name;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
@Define({name: "customName2"})
|
|
58
|
-
test3() {
|
|
59
|
-
// test
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
@Agenda({namespace: "test-nsp-2"})
|
|
64
|
-
class CustomCampaign2 {
|
|
65
|
-
@Define({name: "customName"})
|
|
66
|
-
test(job: Job) {
|
|
67
|
-
// test
|
|
68
|
-
return "hello " + job.attrs.name;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
@Agenda({namespace: "test-nsp-3"})
|
|
73
|
-
class CustomCampaign3 {}
|
|
74
|
-
|
|
75
|
-
describe("AgendaModule", () => {
|
|
76
|
-
describe("when agenda is enabled", () => {
|
|
77
|
-
beforeEach(() =>
|
|
78
|
-
PlatformTest.create({
|
|
79
|
-
agenda: {
|
|
80
|
-
enabled: true
|
|
81
|
-
}
|
|
82
|
-
})
|
|
83
|
-
);
|
|
84
|
-
afterEach(() => PlatformTest.reset());
|
|
85
|
-
|
|
86
|
-
describe("$afterListen()", () => {
|
|
87
|
-
it("should load all jobs", async () => {
|
|
88
|
-
const agendaModule = PlatformTest.get<any>(AgendaModule)!;
|
|
89
|
-
const campaign = PlatformTest.get<CustomCampaign>(CustomCampaign)!;
|
|
90
|
-
|
|
91
|
-
await agendaModule.$afterListen();
|
|
92
|
-
|
|
93
|
-
expect(agendaModule.agenda.define).toHaveBeenCalledWith("test-nsp.test", {}, expect.any(Function));
|
|
94
|
-
expect(agendaModule.agenda.every).toHaveBeenCalledWith("60 seconds", "test-nsp.test", {}, {});
|
|
95
|
-
expect(agendaModule.agenda.start).toHaveBeenCalledWith();
|
|
96
|
-
expect(agendaModule.agenda.create).toHaveBeenCalledWith("customName2", {locale: "fr-FR"});
|
|
97
|
-
|
|
98
|
-
expect(campaign.job.repeatEvery).toHaveBeenCalledWith("1 week");
|
|
99
|
-
expect(campaign.job.save).toHaveBeenCalledWith();
|
|
100
|
-
|
|
101
|
-
const result = await agendaModule.agenda.define.mock.calls[0][2]({
|
|
102
|
-
attrs: {
|
|
103
|
-
name: "test-nsp.test"
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
expect(result).toEqual("hello test-nsp.test");
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
describe("schedule()", () => {
|
|
111
|
-
it("should schedule a job", async () => {
|
|
112
|
-
const agendaModule = PlatformTest.get<any>(AgendaModule)!;
|
|
113
|
-
|
|
114
|
-
await agendaModule.schedule("now", "test-nsp.test", {});
|
|
115
|
-
|
|
116
|
-
expect(agendaModule.agenda.schedule).toHaveBeenCalledWith("now", "test-nsp.test", {});
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
describe("now()", () => {
|
|
121
|
-
it("should schedule a job", async () => {
|
|
122
|
-
const agendaModule = PlatformTest.get<any>(AgendaModule)!;
|
|
123
|
-
|
|
124
|
-
await agendaModule.now("test-nsp.test", {});
|
|
125
|
-
|
|
126
|
-
expect(agendaModule.agenda.now).toHaveBeenCalledWith("test-nsp.test", {});
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
describe("$onDestroy()", () => {
|
|
130
|
-
it("should close agenda", async () => {
|
|
131
|
-
const agendaModule = PlatformTest.get<any>(AgendaModule)!;
|
|
132
|
-
|
|
133
|
-
await agendaModule.$onDestroy();
|
|
134
|
-
|
|
135
|
-
expect(agendaModule.agenda.stop).toHaveBeenCalledWith();
|
|
136
|
-
expect(agendaModule.agenda.close).toHaveBeenCalledWith({force: true});
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
describe("when agenda is enabled and drainJobsBeforeClose = true", () => {
|
|
141
|
-
beforeEach(() =>
|
|
142
|
-
PlatformTest.create({
|
|
143
|
-
agenda: {
|
|
144
|
-
enabled: true,
|
|
145
|
-
drainJobsBeforeClose: true
|
|
146
|
-
}
|
|
147
|
-
})
|
|
148
|
-
);
|
|
149
|
-
afterEach(() => PlatformTest.reset());
|
|
150
|
-
describe("$onDestroy()", () => {
|
|
151
|
-
it("should close agenda", async () => {
|
|
152
|
-
const agendaModule = PlatformTest.get<any>(AgendaModule)!;
|
|
153
|
-
|
|
154
|
-
await agendaModule.$onDestroy();
|
|
155
|
-
|
|
156
|
-
expect(agendaModule.agenda.drain).toHaveBeenCalledWith();
|
|
157
|
-
expect(agendaModule.agenda.close).toHaveBeenCalledWith({force: true});
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
describe("when agenda is enabled but disableJobProcessing = true", () => {
|
|
162
|
-
beforeEach(() =>
|
|
163
|
-
PlatformTest.create({
|
|
164
|
-
agenda: {
|
|
165
|
-
enabled: true,
|
|
166
|
-
disableJobProcessing: true
|
|
167
|
-
}
|
|
168
|
-
})
|
|
169
|
-
);
|
|
170
|
-
afterEach(() => PlatformTest.reset());
|
|
171
|
-
|
|
172
|
-
describe("$afterListen()", () => {
|
|
173
|
-
it("should load all jobs", async () => {
|
|
174
|
-
const agendaModule = PlatformTest.get<any>(AgendaModule)!;
|
|
175
|
-
const campaign = PlatformTest.get<CustomCampaign>(CustomCampaign)!;
|
|
176
|
-
|
|
177
|
-
await agendaModule.$afterListen();
|
|
178
|
-
|
|
179
|
-
expect(agendaModule.agenda.define).not.toHaveBeenCalled();
|
|
180
|
-
expect(agendaModule.agenda.every).not.toHaveBeenCalled();
|
|
181
|
-
expect(agendaModule.agenda.start).toHaveBeenCalledWith();
|
|
182
|
-
expect(agendaModule.agenda.create).not.toHaveBeenCalled();
|
|
183
|
-
|
|
184
|
-
expect(campaign.job).toBeUndefined();
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
describe("when agenda is disabled", () => {
|
|
190
|
-
beforeEach(() =>
|
|
191
|
-
PlatformTest.create({
|
|
192
|
-
agenda: {
|
|
193
|
-
enabled: false
|
|
194
|
-
}
|
|
195
|
-
})
|
|
196
|
-
);
|
|
197
|
-
afterEach(() => PlatformTest.reset());
|
|
198
|
-
|
|
199
|
-
describe("$afterListen()", () => {
|
|
200
|
-
it("should load all jobs", async () => {
|
|
201
|
-
const agendaModule = PlatformTest.get<any>(AgendaModule)!;
|
|
202
|
-
const campaign = PlatformTest.get<CustomCampaign>(CustomCampaign)!;
|
|
203
|
-
|
|
204
|
-
await agendaModule.$afterListen();
|
|
205
|
-
|
|
206
|
-
expect(agendaModule.agenda.define).toBeUndefined();
|
|
207
|
-
|
|
208
|
-
expect(campaign.job).toBeUndefined();
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
describe("$onDestroy()", () => {
|
|
213
|
-
it("should do nothing", async () => {
|
|
214
|
-
const agendaModule = PlatformTest.get<any>(AgendaModule)!;
|
|
215
|
-
|
|
216
|
-
await agendaModule.$onDestroy();
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
});
|
package/src/AgendaModule.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import {AfterListen, DIContext, Logger, OnDestroy, runInContext} from "@tsed/common";
|
|
2
|
-
import {Constant, Inject, InjectorService, Module, Provider} from "@tsed/di";
|
|
3
|
-
import {Job, Processor} from "agenda";
|
|
4
|
-
import {v4 as uuid} from "uuid";
|
|
5
|
-
import {PROVIDER_TYPE_AGENDA} from "./constants/constants.js";
|
|
6
|
-
import {AgendaStore} from "./interfaces/AgendaStore.js";
|
|
7
|
-
import {AgendaService} from "./services/AgendaFactory.js";
|
|
8
|
-
|
|
9
|
-
@Module()
|
|
10
|
-
export class AgendaModule implements OnDestroy, AfterListen {
|
|
11
|
-
@Inject()
|
|
12
|
-
protected logger: Logger;
|
|
13
|
-
|
|
14
|
-
@Inject()
|
|
15
|
-
protected injector: InjectorService;
|
|
16
|
-
|
|
17
|
-
@Inject()
|
|
18
|
-
protected agenda: AgendaService;
|
|
19
|
-
|
|
20
|
-
@Constant("agenda.enabled", false)
|
|
21
|
-
private enabled: boolean;
|
|
22
|
-
|
|
23
|
-
@Constant("agenda.drainJobsBeforeClose", false)
|
|
24
|
-
private drainJobsBeforeClose: boolean;
|
|
25
|
-
|
|
26
|
-
@Constant("agenda.disableJobProcessing", false)
|
|
27
|
-
private disableJobProcessing: boolean;
|
|
28
|
-
|
|
29
|
-
async $afterListen(): Promise<any> {
|
|
30
|
-
if (this.enabled) {
|
|
31
|
-
const providers = this.getProviders();
|
|
32
|
-
|
|
33
|
-
if (!this.disableJobProcessing) {
|
|
34
|
-
this.logger.info({
|
|
35
|
-
event: "AGENDA_ADD_DEFINITIONS",
|
|
36
|
-
message: "Agenda add definitions"
|
|
37
|
-
});
|
|
38
|
-
providers.forEach((provider) => this.addAgendaDefinitionsForProvider(provider));
|
|
39
|
-
|
|
40
|
-
await this.injector.emit("$beforeAgendaStart");
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
await this.agenda.start();
|
|
44
|
-
|
|
45
|
-
if (!this.disableJobProcessing) {
|
|
46
|
-
this.logger.info({
|
|
47
|
-
event: "AGENDA_ADD_JOBS",
|
|
48
|
-
message: "Agenda add scheduled jobs"
|
|
49
|
-
});
|
|
50
|
-
await Promise.all(providers.map((provider) => this.scheduleJobsForProvider(provider)));
|
|
51
|
-
|
|
52
|
-
await this.injector.emit("$afterAgendaStart");
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async $onDestroy(): Promise<any> {
|
|
58
|
-
if (this.enabled) {
|
|
59
|
-
if (this.drainJobsBeforeClose && "drain" in this.agenda) {
|
|
60
|
-
this.logger.info({
|
|
61
|
-
event: "AGENDA_DRAIN",
|
|
62
|
-
message: "Agenda is draining all jobs before close"
|
|
63
|
-
});
|
|
64
|
-
await this.agenda.drain();
|
|
65
|
-
} else {
|
|
66
|
-
this.logger.info({
|
|
67
|
-
event: "AGENDA_STOP",
|
|
68
|
-
message: "Agenda is stopping"
|
|
69
|
-
});
|
|
70
|
-
await this.agenda.stop();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
await this.agenda.close({force: true});
|
|
74
|
-
|
|
75
|
-
this.logger.info({event: "AGENDA_STOP", message: "Agenda stopped"});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
define(name: string, options?: any, processor?: any) {
|
|
80
|
-
return this.agenda.define(name, options, (job: Job) => {
|
|
81
|
-
const $ctx = new DIContext({
|
|
82
|
-
injector: this.injector,
|
|
83
|
-
id: uuid(),
|
|
84
|
-
logger: this.injector.logger
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
$ctx.set("job", job);
|
|
88
|
-
|
|
89
|
-
return runInContext($ctx, () => processor(job));
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
every(interval: string, name: string, data?: any, options?: any) {
|
|
94
|
-
return this.agenda.every(interval, name, data, options);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
schedule(when: Date | string, name: string, data?: any) {
|
|
98
|
-
return this.agenda.schedule(when, name, data);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
now(name: string, data?: any) {
|
|
102
|
-
return this.agenda.now(name, data);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
create(name: string, data?: any) {
|
|
106
|
-
return this.agenda.create(name, data);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
protected getProviders(): Provider<any>[] {
|
|
110
|
-
return this.injector.getProviders(PROVIDER_TYPE_AGENDA);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
protected addAgendaDefinitionsForProvider(provider: Provider): void {
|
|
114
|
-
const store = provider.store.get<AgendaStore>("agenda", {});
|
|
115
|
-
|
|
116
|
-
if (!store.define) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
Object.entries(store.define).forEach(([propertyKey, {name, ...options}]) => {
|
|
121
|
-
const instance = this.injector.get(provider.token);
|
|
122
|
-
|
|
123
|
-
const jobProcessor: Processor<unknown> = instance[propertyKey].bind(instance) as Processor<unknown>;
|
|
124
|
-
const jobName = this.getNameForJob(propertyKey, store.namespace, name);
|
|
125
|
-
|
|
126
|
-
this.define(jobName, options, jobProcessor);
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
protected async scheduleJobsForProvider(provider: Provider<any>): Promise<void> {
|
|
131
|
-
const store = provider.store.get<AgendaStore>("agenda", {});
|
|
132
|
-
|
|
133
|
-
if (!store.every) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const promises = Object.entries(store.every).map(([propertyKey, {interval, name, ...options}]) => {
|
|
138
|
-
const jobName = this.getNameForJob(propertyKey, store.namespace, name);
|
|
139
|
-
|
|
140
|
-
return this.every(interval, jobName, {}, options);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
await Promise.all(promises);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
protected getNameForJob(propertyKey: string, namespace?: string, customName?: string): string {
|
|
147
|
-
const name = customName || propertyKey;
|
|
148
|
-
return namespace ? `${namespace}.${name}` : name;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const PROVIDER_TYPE_AGENDA = "PROVIDER_TYPE_AGENDA";
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {Store} from "@tsed/core";
|
|
2
|
-
import {Agenda} from "./agenda.js";
|
|
3
|
-
|
|
4
|
-
describe("@Agenda()", () => {
|
|
5
|
-
it("should set empty metadata", () => {
|
|
6
|
-
@Agenda()
|
|
7
|
-
class Test {}
|
|
8
|
-
|
|
9
|
-
const store = Store.from(Test);
|
|
10
|
-
expect(store.get("agenda")).toEqual(undefined);
|
|
11
|
-
});
|
|
12
|
-
it("should set namespace metadata", () => {
|
|
13
|
-
@Agenda({namespace: "nsp1"})
|
|
14
|
-
class Test {}
|
|
15
|
-
|
|
16
|
-
const store = Store.from(Test);
|
|
17
|
-
expect(store.get("agenda")).toEqual({
|
|
18
|
-
namespace: "nsp1"
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
});
|
package/src/decorators/agenda.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {StoreMerge, useDecorators} from "@tsed/core";
|
|
2
|
-
import {Injectable} from "@tsed/di";
|
|
3
|
-
import {PROVIDER_TYPE_AGENDA} from "../constants/constants.js";
|
|
4
|
-
|
|
5
|
-
interface AgendaOptions {
|
|
6
|
-
namespace?: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function Agenda(options?: AgendaOptions): ClassDecorator {
|
|
10
|
-
return useDecorators(
|
|
11
|
-
options?.namespace && StoreMerge("agenda", options),
|
|
12
|
-
Injectable({
|
|
13
|
-
type: PROVIDER_TYPE_AGENDA
|
|
14
|
-
})
|
|
15
|
-
);
|
|
16
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import {Store} from "@tsed/core";
|
|
2
|
-
import {Agenda} from "./agenda.js";
|
|
3
|
-
import {Define} from "./define.js";
|
|
4
|
-
|
|
5
|
-
describe("@Define()", () => {
|
|
6
|
-
it("should set empty metadata", () => {
|
|
7
|
-
@Agenda()
|
|
8
|
-
class Test {
|
|
9
|
-
@Define()
|
|
10
|
-
testDefineDecorator() {
|
|
11
|
-
// test
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
@Define()
|
|
15
|
-
testDefineDecorator2() {
|
|
16
|
-
// test 2
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const store = Store.from(Test);
|
|
21
|
-
|
|
22
|
-
expect(store.get("agenda").define).toEqual({
|
|
23
|
-
testDefineDecorator: {},
|
|
24
|
-
testDefineDecorator2: {}
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("should set options metadata", () => {
|
|
29
|
-
@Agenda()
|
|
30
|
-
class Test {
|
|
31
|
-
@Define({
|
|
32
|
-
name: "testDefineDecoratorCustomName",
|
|
33
|
-
priority: 20
|
|
34
|
-
})
|
|
35
|
-
test() {
|
|
36
|
-
// test
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const store = Store.from(Test);
|
|
41
|
-
expect(store.get("agenda").define).toEqual({
|
|
42
|
-
test: {
|
|
43
|
-
name: "testDefineDecoratorCustomName",
|
|
44
|
-
priority: 20
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
});
|
package/src/decorators/define.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {Store} from "@tsed/core";
|
|
2
|
-
import {AgendaStore, DefineOptions} from "../interfaces/AgendaStore.js";
|
|
3
|
-
|
|
4
|
-
export function Define(options: DefineOptions = {}): MethodDecorator {
|
|
5
|
-
return (target: any, propertyKey: string) => {
|
|
6
|
-
const store: AgendaStore = {
|
|
7
|
-
define: {
|
|
8
|
-
[propertyKey]: options
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
Store.from(target).merge("agenda", store);
|
|
13
|
-
};
|
|
14
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import {descriptorOf, Store} from "@tsed/core";
|
|
2
|
-
import {Agenda} from "./agenda.js";
|
|
3
|
-
import {Every} from "./every.js";
|
|
4
|
-
|
|
5
|
-
describe("@Every()", () => {
|
|
6
|
-
it("should set metadata", () => {
|
|
7
|
-
@Agenda()
|
|
8
|
-
class Test {
|
|
9
|
-
@Every("60 seconds")
|
|
10
|
-
testEveryDecorator() {
|
|
11
|
-
// test
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
@Every("* * * * *")
|
|
15
|
-
testEveryDecorator2() {
|
|
16
|
-
// test 2
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const store = Store.from(Test);
|
|
21
|
-
|
|
22
|
-
expect(store.get("agenda").define).toEqual({
|
|
23
|
-
testEveryDecorator: {},
|
|
24
|
-
testEveryDecorator2: {}
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
expect(store.get("agenda").every).toEqual({
|
|
28
|
-
testEveryDecorator: {
|
|
29
|
-
interval: "60 seconds"
|
|
30
|
-
},
|
|
31
|
-
testEveryDecorator2: {
|
|
32
|
-
interval: "* * * * *"
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
});
|
package/src/decorators/every.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {Store, useDecorators} from "@tsed/core";
|
|
2
|
-
import {Define} from "./define.js";
|
|
3
|
-
import {AgendaStore, EveryOptions} from "../interfaces/AgendaStore.js";
|
|
4
|
-
|
|
5
|
-
export function Every(interval: string, options: EveryOptions = {}): MethodDecorator {
|
|
6
|
-
return useDecorators(Define(options), (target: any, propertyKey: string) => {
|
|
7
|
-
const store: AgendaStore = {
|
|
8
|
-
every: {
|
|
9
|
-
[propertyKey]: {...options, interval}
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
Store.from(target).merge("agenda", store);
|
|
13
|
-
});
|
|
14
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Automatically generated by @tsed/barrels.
|
|
3
|
-
*/
|
|
4
|
-
export * from "./AgendaModule.js";
|
|
5
|
-
export * from "./constants/constants.js";
|
|
6
|
-
export * from "./decorators/agenda.js";
|
|
7
|
-
export * from "./decorators/define.js";
|
|
8
|
-
export * from "./decorators/every.js";
|
|
9
|
-
export * from "./interfaces/AgendaStore.js";
|
|
10
|
-
export * from "./interfaces/interfaces.js";
|
|
11
|
-
export * from "./services/AgendaFactory.js";
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import {DefineOptions as AgendaDefineOptions, JobOptions} from "agenda";
|
|
2
|
-
|
|
3
|
-
export interface DefineOptions extends AgendaDefineOptions {
|
|
4
|
-
name?: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export type EveryOptions = JobOptions & DefineOptions;
|
|
8
|
-
|
|
9
|
-
export interface AgendaStore {
|
|
10
|
-
namespace?: string;
|
|
11
|
-
define?: {[propertyKey: string]: DefineOptions};
|
|
12
|
-
every?: {[propertyKey: string]: EveryOptions & {interval: string}};
|
|
13
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {AgendaConfig} from "agenda";
|
|
2
|
-
|
|
3
|
-
declare global {
|
|
4
|
-
namespace TsED {
|
|
5
|
-
interface Configuration {
|
|
6
|
-
agenda?: {
|
|
7
|
-
/**
|
|
8
|
-
* Enable Agenda jobs. Default false.
|
|
9
|
-
*/
|
|
10
|
-
enabled?: boolean;
|
|
11
|
-
disableJobProcessing?: boolean;
|
|
12
|
-
drainJobsBeforeClose?: boolean;
|
|
13
|
-
} & AgendaConfig;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import {Configuration, registerProvider} from "@tsed/di";
|
|
2
|
-
import {Agenda, AgendaConfig} from "agenda";
|
|
3
|
-
|
|
4
|
-
// create Alias to avoid confusing import between Agenda from "agenda" and Agenda decorator
|
|
5
|
-
export const AgendaService = Agenda;
|
|
6
|
-
export type AgendaService = Agenda;
|
|
7
|
-
|
|
8
|
-
registerProvider({
|
|
9
|
-
provide: Agenda,
|
|
10
|
-
deps: [Configuration],
|
|
11
|
-
useFactory(settings: Configuration) {
|
|
12
|
-
const opts = settings.get<AgendaConfig & {enabled: boolean}>("agenda", {enabled: false});
|
|
13
|
-
return opts.enabled ? new Agenda(opts) : {};
|
|
14
|
-
}
|
|
15
|
-
});
|
package/tsconfig.esm.json
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@tsed/typescript/tsconfig.node.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"baseUrl": ".",
|
|
5
|
-
"module": "ES2020",
|
|
6
|
-
"rootDir": "src",
|
|
7
|
-
"outDir": "./lib/esm",
|
|
8
|
-
"declaration": true,
|
|
9
|
-
"declarationDir": "./lib/types",
|
|
10
|
-
"composite": true,
|
|
11
|
-
"noEmit": false
|
|
12
|
-
},
|
|
13
|
-
"include": ["src", "src/**/*.json"],
|
|
14
|
-
"exclude": [
|
|
15
|
-
"node_modules",
|
|
16
|
-
"test",
|
|
17
|
-
"lib",
|
|
18
|
-
"benchmark",
|
|
19
|
-
"coverage",
|
|
20
|
-
"spec",
|
|
21
|
-
"**/*.benchmark.ts",
|
|
22
|
-
"**/*.spec.ts",
|
|
23
|
-
"keys",
|
|
24
|
-
"jest.config.js",
|
|
25
|
-
"**/__mock__/**",
|
|
26
|
-
"webpack.config.js"
|
|
27
|
-
],
|
|
28
|
-
"references": [
|
|
29
|
-
{
|
|
30
|
-
"path": "../../platform/common"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"path": "../../core"
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
"path": "../../di"
|
|
37
|
-
}
|
|
38
|
-
]
|
|
39
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@tsed/typescript/tsconfig.node.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"baseUrl": ".",
|
|
5
|
-
"module": "commonjs",
|
|
6
|
-
"rootDir": "src",
|
|
7
|
-
"outDir": "./lib/cjs",
|
|
8
|
-
"declaration": true,
|
|
9
|
-
"declarationDir": "./lib/types",
|
|
10
|
-
"composite": true,
|
|
11
|
-
"noEmit": false
|
|
12
|
-
},
|
|
13
|
-
"include": ["src", "src/**/*.json"],
|
|
14
|
-
"exclude": [
|
|
15
|
-
"node_modules",
|
|
16
|
-
"test",
|
|
17
|
-
"lib",
|
|
18
|
-
"benchmark",
|
|
19
|
-
"coverage",
|
|
20
|
-
"spec",
|
|
21
|
-
"**/*.benchmark.ts",
|
|
22
|
-
"**/*.spec.ts",
|
|
23
|
-
"keys",
|
|
24
|
-
"jest.config.js",
|
|
25
|
-
"**/__mock__/**",
|
|
26
|
-
"webpack.config.js"
|
|
27
|
-
],
|
|
28
|
-
"references": [
|
|
29
|
-
{
|
|
30
|
-
"path": "../../platform/common"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"path": "../../core"
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
"path": "../../di"
|
|
37
|
-
}
|
|
38
|
-
]
|
|
39
|
-
}
|