@nest-omni/core 3.1.1-14 → 3.1.1-16
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/cache/cache.module.js +6 -2
- package/package.json +1 -1
- package/shared/serviceRegistryModule.js +0 -2
- package/cache/examples/quick-start.d.ts +0 -5
- package/cache/examples/quick-start.js +0 -341
- package/redis-lock/redis-lock.examples.d.ts +0 -13
- package/redis-lock/redis-lock.examples.js +0 -159
- package/setup/schedule.decorator.examples.d.ts +0 -18
- package/setup/schedule.decorator.examples.js +0 -255
package/cache/cache.module.js
CHANGED
|
@@ -53,7 +53,7 @@ let CacheModule = CacheModule_1 = class CacheModule {
|
|
|
53
53
|
},
|
|
54
54
|
cache_service_1.CacheService,
|
|
55
55
|
],
|
|
56
|
-
exports: [
|
|
56
|
+
exports: [exports.CACHE_SERVICE, cache_service_1.CacheService],
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
static forRootAsync(options) {
|
|
@@ -88,9 +88,13 @@ let CacheModule = CacheModule_1 = class CacheModule {
|
|
|
88
88
|
inject: ['CACHE_MODULE_OPTIONS'],
|
|
89
89
|
},
|
|
90
90
|
providers_1.RedisCacheProvider,
|
|
91
|
+
{
|
|
92
|
+
provide: exports.CACHE_SERVICE,
|
|
93
|
+
useClass: cache_service_1.CacheService,
|
|
94
|
+
},
|
|
91
95
|
cache_service_1.CacheService,
|
|
92
96
|
],
|
|
93
|
-
exports: [cache_service_1.CacheService],
|
|
97
|
+
exports: [exports.CACHE_SERVICE, cache_service_1.CacheService],
|
|
94
98
|
};
|
|
95
99
|
}
|
|
96
100
|
onModuleInit() {
|
package/package.json
CHANGED
|
@@ -107,7 +107,6 @@ if (services_1.ApiConfigService.toBoolean(process.env.BULL_ENABLED)) {
|
|
|
107
107
|
}
|
|
108
108
|
if (services_1.ApiConfigService.toBoolean(process.env.CACHE_ENABLED)) {
|
|
109
109
|
modules.push(cache_1.CacheModule.forRootAsync({
|
|
110
|
-
imports: [nestjs_redis_1.RedisModule],
|
|
111
110
|
inject: [services_1.ApiConfigService, nestjs_redis_1.RedisService, typeorm_2.DataSource],
|
|
112
111
|
isGlobal: true,
|
|
113
112
|
useFactory: (config, redisService, dataSource) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -131,7 +130,6 @@ if (services_1.ApiConfigService.toBoolean(process.env.CACHE_ENABLED)) {
|
|
|
131
130
|
if (services_1.ApiConfigService.toBoolean(process.env.SCHEDULE_ENABLED) &&
|
|
132
131
|
services_1.ApiConfigService.toBoolean(process.env.REDIS_LOCK_ENABLED, true)) {
|
|
133
132
|
modules.push(redis_lock_1.RedisLockModule.forRootAsync({
|
|
134
|
-
imports: [nestjs_redis_1.RedisModule],
|
|
135
133
|
inject: [services_1.ApiConfigService, nestjs_redis_1.RedisService],
|
|
136
134
|
isGlobal: true,
|
|
137
135
|
useFactory: (config, redisService) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -1,341 +0,0 @@
|
|
|
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 __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.UserModule = exports.ExampleAppModule = exports.AppModule = void 0;
|
|
25
|
-
const common_1 = require("@nestjs/common");
|
|
26
|
-
const index_1 = require("../index");
|
|
27
|
-
let AppModule = class AppModule {
|
|
28
|
-
};
|
|
29
|
-
exports.AppModule = AppModule;
|
|
30
|
-
exports.ExampleAppModule = AppModule;
|
|
31
|
-
exports.ExampleAppModule = exports.AppModule = AppModule = __decorate([
|
|
32
|
-
(0, common_1.Module)({
|
|
33
|
-
imports: [
|
|
34
|
-
index_1.CacheModule.forRoot({
|
|
35
|
-
memoryTtl: 300000,
|
|
36
|
-
}),
|
|
37
|
-
],
|
|
38
|
-
})
|
|
39
|
-
], AppModule);
|
|
40
|
-
let UserService = class UserService {
|
|
41
|
-
constructor(cacheService) {
|
|
42
|
-
this.cacheService = cacheService;
|
|
43
|
-
}
|
|
44
|
-
getUserDirect(id) {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
return yield this.cacheService.getOrSet(`user:${id}`, () => __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
yield new Promise((resolve) => setTimeout(resolve, 50));
|
|
48
|
-
return { id, name: `User ${id}`, email: `user${id}@example.com` };
|
|
49
|
-
}), {
|
|
50
|
-
ttl: 300000,
|
|
51
|
-
dependencies: [new index_1.TagDependency(['user-data'])],
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
getUserWithDecorator(id) {
|
|
56
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
yield new Promise((resolve) => setTimeout(resolve, 50));
|
|
58
|
-
return { id, name: `User ${id}`, email: `user${id}@example.com` };
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
getUserProfile(id) {
|
|
62
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
const user = yield this.getUserWithDecorator(id);
|
|
64
|
-
return Object.assign(Object.assign({}, user), { profile: {
|
|
65
|
-
bio: `Bio for ${user.name}`,
|
|
66
|
-
avatar: `https://avatar.com/${id}.jpg`,
|
|
67
|
-
settings: { theme: 'dark' },
|
|
68
|
-
} });
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
getUserFull(id) {
|
|
72
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
const user = yield this.getUserWithDecorator(id);
|
|
74
|
-
const profile = yield this.getUserProfile(id);
|
|
75
|
-
return Object.assign(Object.assign({}, user), { profile, permissions: ['read', 'write'], lastLogin: new Date() });
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
getUserList() {
|
|
79
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
yield new Promise((resolve) => setTimeout(resolve, 100));
|
|
81
|
-
return [
|
|
82
|
-
{ id: '1', name: 'John Doe', email: 'john@example.com' },
|
|
83
|
-
{ id: '2', name: 'Jane Smith', email: 'jane@example.com' },
|
|
84
|
-
{ id: '3', name: 'Bob Johnson', email: 'bob@example.com' },
|
|
85
|
-
];
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
searchUsers(query) {
|
|
89
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
const users = yield this.getUserList();
|
|
91
|
-
return users.filter((user) => user.name.toLowerCase().includes(query.toLowerCase()) ||
|
|
92
|
-
user.email.toLowerCase().includes(query.toLowerCase()));
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
updateUser(id, data) {
|
|
96
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
yield new Promise((resolve) => setTimeout(resolve, 50));
|
|
98
|
-
const existing = yield this.getUserWithDecorator(id);
|
|
99
|
-
return Object.assign(Object.assign(Object.assign({}, existing), data), { updatedAt: new Date() });
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
deleteUser(id) {
|
|
103
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
-
yield new Promise((resolve) => setTimeout(resolve, 20));
|
|
105
|
-
return true;
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
clearAllUserCache() {
|
|
109
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
batchGetUsers(ids) {
|
|
113
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
const keys = ids.map((id) => `user:${id}:decorated`);
|
|
115
|
-
const cached = yield this.cacheService.mget(keys);
|
|
116
|
-
const uncachedIds = ids.filter((id, index) => !cached[index]);
|
|
117
|
-
if (uncachedIds.length > 0) {
|
|
118
|
-
const uncachedUsers = yield Promise.all(uncachedIds.map((id) => this.getUserWithDecorator(id)));
|
|
119
|
-
const items = uncachedIds.map((id, index) => ({
|
|
120
|
-
key: `user:${id}:decorated`,
|
|
121
|
-
value: uncachedUsers[index],
|
|
122
|
-
}));
|
|
123
|
-
yield this.cacheService.mset(items, { ttl: 300000 });
|
|
124
|
-
}
|
|
125
|
-
return cached.filter(Boolean);
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
getCacheStats() {
|
|
129
|
-
return this.cacheService.getStats();
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
__decorate([
|
|
133
|
-
(0, index_1.Cacheable)({
|
|
134
|
-
key: (id) => `user:${id}:decorated`,
|
|
135
|
-
ttl: 300000,
|
|
136
|
-
layers: [index_1.CacheLayer.MEMORY, index_1.CacheLayer.REDIS],
|
|
137
|
-
dependencies: [
|
|
138
|
-
new index_1.TagDependency(['user-data']),
|
|
139
|
-
new index_1.CallbackDependency(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
140
|
-
return 'user-version-1';
|
|
141
|
-
})),
|
|
142
|
-
],
|
|
143
|
-
}),
|
|
144
|
-
__metadata("design:type", Function),
|
|
145
|
-
__metadata("design:paramtypes", [String]),
|
|
146
|
-
__metadata("design:returntype", Promise)
|
|
147
|
-
], UserService.prototype, "getUserWithDecorator", null);
|
|
148
|
-
__decorate([
|
|
149
|
-
(0, index_1.Cacheable)({
|
|
150
|
-
key: (id) => `user:${id}:profile`,
|
|
151
|
-
condition: (id) => id !== 'admin',
|
|
152
|
-
dependencies: [new index_1.TagDependency(['user-profile'])],
|
|
153
|
-
}),
|
|
154
|
-
__metadata("design:type", Function),
|
|
155
|
-
__metadata("design:paramtypes", [String]),
|
|
156
|
-
__metadata("design:returntype", Promise)
|
|
157
|
-
], UserService.prototype, "getUserProfile", null);
|
|
158
|
-
__decorate([
|
|
159
|
-
(0, index_1.Cacheable)({
|
|
160
|
-
key: (id) => `user:${id}:full`,
|
|
161
|
-
dependencies: [
|
|
162
|
-
new index_1.DbDependency('SELECT updated_at FROM users WHERE id = ?', (id) => [id]),
|
|
163
|
-
],
|
|
164
|
-
}),
|
|
165
|
-
__metadata("design:type", Function),
|
|
166
|
-
__metadata("design:paramtypes", [String]),
|
|
167
|
-
__metadata("design:returntype", Promise)
|
|
168
|
-
], UserService.prototype, "getUserFull", null);
|
|
169
|
-
__decorate([
|
|
170
|
-
(0, index_1.Cacheable)({
|
|
171
|
-
key: 'users:list',
|
|
172
|
-
ttl: 600000,
|
|
173
|
-
dependencies: [new index_1.TagDependency(['user-list', 'all-users'])],
|
|
174
|
-
}),
|
|
175
|
-
__metadata("design:type", Function),
|
|
176
|
-
__metadata("design:paramtypes", []),
|
|
177
|
-
__metadata("design:returntype", Promise)
|
|
178
|
-
], UserService.prototype, "getUserList", null);
|
|
179
|
-
__decorate([
|
|
180
|
-
(0, index_1.Cacheable)({
|
|
181
|
-
key: (query) => `users:search:${query.toLowerCase()}`,
|
|
182
|
-
condition: (query) => query.length >= 2,
|
|
183
|
-
ttl: 1800000,
|
|
184
|
-
}),
|
|
185
|
-
__metadata("design:type", Function),
|
|
186
|
-
__metadata("design:paramtypes", [String]),
|
|
187
|
-
__metadata("design:returntype", Promise)
|
|
188
|
-
], UserService.prototype, "searchUsers", null);
|
|
189
|
-
__decorate([
|
|
190
|
-
(0, index_1.CachePut)({
|
|
191
|
-
key: (id) => `user:${id}:decorated`,
|
|
192
|
-
dependencies: [new index_1.TagDependency(['user-data'])],
|
|
193
|
-
}),
|
|
194
|
-
__metadata("design:type", Function),
|
|
195
|
-
__metadata("design:paramtypes", [String, Object]),
|
|
196
|
-
__metadata("design:returntype", Promise)
|
|
197
|
-
], UserService.prototype, "updateUser", null);
|
|
198
|
-
__decorate([
|
|
199
|
-
(0, index_1.CacheEvict)({
|
|
200
|
-
keys: [
|
|
201
|
-
(id) => `user:${id}`,
|
|
202
|
-
(id) => `user:${id}:decorated`,
|
|
203
|
-
(id) => `user:${id}:profile`,
|
|
204
|
-
(id) => `user:${id}:full`,
|
|
205
|
-
],
|
|
206
|
-
tags: ['user-data'],
|
|
207
|
-
}),
|
|
208
|
-
__metadata("design:type", Function),
|
|
209
|
-
__metadata("design:paramtypes", [String]),
|
|
210
|
-
__metadata("design:returntype", Promise)
|
|
211
|
-
], UserService.prototype, "deleteUser", null);
|
|
212
|
-
__decorate([
|
|
213
|
-
(0, index_1.CacheEvict)({
|
|
214
|
-
patterns: ['user:*', 'users:*'],
|
|
215
|
-
tags: ['user-data', 'user-list', 'all-users'],
|
|
216
|
-
}),
|
|
217
|
-
__metadata("design:type", Function),
|
|
218
|
-
__metadata("design:paramtypes", []),
|
|
219
|
-
__metadata("design:returntype", Promise)
|
|
220
|
-
], UserService.prototype, "clearAllUserCache", null);
|
|
221
|
-
UserService = __decorate([
|
|
222
|
-
(0, common_1.Injectable)(),
|
|
223
|
-
__metadata("design:paramtypes", [index_1.CacheService])
|
|
224
|
-
], UserService);
|
|
225
|
-
let UserController = class UserController {
|
|
226
|
-
constructor(userService) {
|
|
227
|
-
this.userService = userService;
|
|
228
|
-
}
|
|
229
|
-
getUser(id) {
|
|
230
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
231
|
-
return yield this.userService.getUserWithDecorator(id);
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
getUserProfile(id) {
|
|
235
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
236
|
-
return yield this.userService.getUserProfile(id);
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
getUserList() {
|
|
240
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
-
return yield this.userService.getUserList();
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
searchUsers(query) {
|
|
245
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
246
|
-
return yield this.userService.searchUsers(query);
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
updateUser(id, data) {
|
|
250
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
251
|
-
return yield this.userService.updateUser(id, data);
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
deleteUser(id) {
|
|
255
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
256
|
-
const deleted = yield this.userService.deleteUser(id);
|
|
257
|
-
return { success: deleted };
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
clearCache() {
|
|
261
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
262
|
-
yield this.userService.clearAllUserCache();
|
|
263
|
-
return { message: 'User cache cleared' };
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
getCacheStats() {
|
|
267
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
268
|
-
return this.userService.getCacheStats();
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
__decorate([
|
|
273
|
-
(0, common_1.Get)(':id'),
|
|
274
|
-
__param(0, (0, common_1.Param)('id')),
|
|
275
|
-
__metadata("design:type", Function),
|
|
276
|
-
__metadata("design:paramtypes", [String]),
|
|
277
|
-
__metadata("design:returntype", Promise)
|
|
278
|
-
], UserController.prototype, "getUser", null);
|
|
279
|
-
__decorate([
|
|
280
|
-
(0, common_1.Get)(':id/profile'),
|
|
281
|
-
__param(0, (0, common_1.Param)('id')),
|
|
282
|
-
__metadata("design:type", Function),
|
|
283
|
-
__metadata("design:paramtypes", [String]),
|
|
284
|
-
__metadata("design:returntype", Promise)
|
|
285
|
-
], UserController.prototype, "getUserProfile", null);
|
|
286
|
-
__decorate([
|
|
287
|
-
(0, common_1.Get)(),
|
|
288
|
-
__metadata("design:type", Function),
|
|
289
|
-
__metadata("design:paramtypes", []),
|
|
290
|
-
__metadata("design:returntype", Promise)
|
|
291
|
-
], UserController.prototype, "getUserList", null);
|
|
292
|
-
__decorate([
|
|
293
|
-
(0, common_1.Get)('search/:query'),
|
|
294
|
-
__param(0, (0, common_1.Param)('query')),
|
|
295
|
-
__metadata("design:type", Function),
|
|
296
|
-
__metadata("design:paramtypes", [String]),
|
|
297
|
-
__metadata("design:returntype", Promise)
|
|
298
|
-
], UserController.prototype, "searchUsers", null);
|
|
299
|
-
__decorate([
|
|
300
|
-
(0, common_1.Post)(':id'),
|
|
301
|
-
__param(0, (0, common_1.Param)('id')),
|
|
302
|
-
__param(1, (0, common_1.Body)()),
|
|
303
|
-
__metadata("design:type", Function),
|
|
304
|
-
__metadata("design:paramtypes", [String, Object]),
|
|
305
|
-
__metadata("design:returntype", Promise)
|
|
306
|
-
], UserController.prototype, "updateUser", null);
|
|
307
|
-
__decorate([
|
|
308
|
-
(0, common_1.Post)(':id/delete'),
|
|
309
|
-
__param(0, (0, common_1.Param)('id')),
|
|
310
|
-
__metadata("design:type", Function),
|
|
311
|
-
__metadata("design:paramtypes", [String]),
|
|
312
|
-
__metadata("design:returntype", Promise)
|
|
313
|
-
], UserController.prototype, "deleteUser", null);
|
|
314
|
-
__decorate([
|
|
315
|
-
(0, common_1.Post)('clear-cache'),
|
|
316
|
-
__metadata("design:type", Function),
|
|
317
|
-
__metadata("design:paramtypes", []),
|
|
318
|
-
__metadata("design:returntype", Promise)
|
|
319
|
-
], UserController.prototype, "clearCache", null);
|
|
320
|
-
__decorate([
|
|
321
|
-
(0, common_1.Get)('cache/stats'),
|
|
322
|
-
__metadata("design:type", Function),
|
|
323
|
-
__metadata("design:paramtypes", []),
|
|
324
|
-
__metadata("design:returntype", Promise)
|
|
325
|
-
], UserController.prototype, "getCacheStats", null);
|
|
326
|
-
UserController = __decorate([
|
|
327
|
-
(0, common_1.Controller)('users'),
|
|
328
|
-
__metadata("design:paramtypes", [UserService])
|
|
329
|
-
], UserController);
|
|
330
|
-
let UserModuleInternal = class UserModuleInternal {
|
|
331
|
-
};
|
|
332
|
-
UserModuleInternal = __decorate([
|
|
333
|
-
(0, common_1.Module)({
|
|
334
|
-
imports: [AppModule],
|
|
335
|
-
controllers: [UserController],
|
|
336
|
-
providers: [UserService],
|
|
337
|
-
})
|
|
338
|
-
], UserModuleInternal);
|
|
339
|
-
class UserModule {
|
|
340
|
-
}
|
|
341
|
-
exports.UserModule = UserModule;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare class ExampleService {
|
|
2
|
-
private readonly logger;
|
|
3
|
-
syncData(): Promise<void>;
|
|
4
|
-
criticalTask(): Promise<void>;
|
|
5
|
-
cleanupTask(): Promise<string>;
|
|
6
|
-
processWithManualLock(data: any): Promise<boolean>;
|
|
7
|
-
processWithWithLock(data: any): Promise<boolean>;
|
|
8
|
-
generateHourlyReport(): Promise<void>;
|
|
9
|
-
private performCriticalOperation;
|
|
10
|
-
private performCleanup;
|
|
11
|
-
private processData;
|
|
12
|
-
private createReport;
|
|
13
|
-
}
|
|
@@ -1,159 +0,0 @@
|
|
|
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
|
-
var ExampleService_1;
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.ExampleService = void 0;
|
|
23
|
-
const common_1 = require("@nestjs/common");
|
|
24
|
-
const redis_lock_decorator_1 = require("./redis-lock.decorator");
|
|
25
|
-
const redis_lock_service_1 = require("./redis-lock.service");
|
|
26
|
-
let ExampleService = ExampleService_1 = class ExampleService {
|
|
27
|
-
constructor() {
|
|
28
|
-
this.logger = new common_1.Logger(ExampleService_1.name);
|
|
29
|
-
}
|
|
30
|
-
syncData() {
|
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
this.logger.log('Starting data synchronization...');
|
|
33
|
-
yield new Promise((resolve) => setTimeout(resolve, 2000));
|
|
34
|
-
this.logger.log('Data synchronization completed');
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
criticalTask() {
|
|
38
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
this.logger.log('Executing critical task...');
|
|
40
|
-
yield this.performCriticalOperation();
|
|
41
|
-
this.logger.log('Critical task completed');
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
cleanupTask() {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
this.logger.log('Starting cleanup task...');
|
|
47
|
-
yield this.performCleanup();
|
|
48
|
-
this.logger.log('Cleanup task completed');
|
|
49
|
-
return 'completed';
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
processWithManualLock(data) {
|
|
53
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
const lockService = new redis_lock_service_1.RedisLockService();
|
|
55
|
-
try {
|
|
56
|
-
const lockResult = yield lockService.acquireLock('process-data', {
|
|
57
|
-
ttl: 60000,
|
|
58
|
-
retryCount: 5,
|
|
59
|
-
retryDelay: 100,
|
|
60
|
-
});
|
|
61
|
-
if (!lockResult.acquired) {
|
|
62
|
-
this.logger.warn('Could not acquire lock, skipping processing');
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
this.logger.log('Lock acquired, processing data...');
|
|
66
|
-
try {
|
|
67
|
-
yield this.processData(data);
|
|
68
|
-
this.logger.log('Data processing completed');
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
finally {
|
|
72
|
-
yield lockService.releaseLock('process-data', lockResult.lockValue);
|
|
73
|
-
this.logger.log('Lock released');
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
this.logger.error('Error in processWithManualLock:', error);
|
|
78
|
-
throw error;
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
processWithWithLock(data) {
|
|
83
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
const lockService = new redis_lock_service_1.RedisLockService();
|
|
85
|
-
return yield lockService.withLock('auto-process', () => __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
this.logger.log('Processing with automatic lock management...');
|
|
87
|
-
yield this.processData(data);
|
|
88
|
-
this.logger.log('Processing completed');
|
|
89
|
-
return true;
|
|
90
|
-
}), {
|
|
91
|
-
ttl: 60000,
|
|
92
|
-
retryCount: 3,
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
generateHourlyReport() {
|
|
97
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
this.logger.log('Generating hourly report...');
|
|
99
|
-
yield this.createReport();
|
|
100
|
-
this.logger.log('Hourly report generated');
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
performCriticalOperation() {
|
|
104
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
yield new Promise((resolve) => setTimeout(resolve, 1000));
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
performCleanup() {
|
|
109
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
-
yield new Promise((resolve) => setTimeout(resolve, 1500));
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
processData(data) {
|
|
114
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
-
yield new Promise((resolve) => setTimeout(resolve, 800));
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
createReport() {
|
|
119
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
-
yield new Promise((resolve) => setTimeout(resolve, 2000));
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
exports.ExampleService = ExampleService;
|
|
125
|
-
__decorate([
|
|
126
|
-
(0, redis_lock_decorator_1.UseRedisLock)('data-sync', { ttl: 300000 }),
|
|
127
|
-
__metadata("design:type", Function),
|
|
128
|
-
__metadata("design:paramtypes", []),
|
|
129
|
-
__metadata("design:returntype", Promise)
|
|
130
|
-
], ExampleService.prototype, "syncData", null);
|
|
131
|
-
__decorate([
|
|
132
|
-
(0, redis_lock_decorator_1.UseRedisLock)('critical-task', {
|
|
133
|
-
ttl: 60000,
|
|
134
|
-
retryCount: 3,
|
|
135
|
-
retryDelay: 200,
|
|
136
|
-
throwOnFailure: true,
|
|
137
|
-
}),
|
|
138
|
-
__metadata("design:type", Function),
|
|
139
|
-
__metadata("design:paramtypes", []),
|
|
140
|
-
__metadata("design:returntype", Promise)
|
|
141
|
-
], ExampleService.prototype, "criticalTask", null);
|
|
142
|
-
__decorate([
|
|
143
|
-
(0, redis_lock_decorator_1.UseRedisLock)('cleanup-task', {
|
|
144
|
-
ttl: 120000,
|
|
145
|
-
skipReturnValue: 'skipped',
|
|
146
|
-
}),
|
|
147
|
-
__metadata("design:type", Function),
|
|
148
|
-
__metadata("design:paramtypes", []),
|
|
149
|
-
__metadata("design:returntype", Promise)
|
|
150
|
-
], ExampleService.prototype, "cleanupTask", null);
|
|
151
|
-
__decorate([
|
|
152
|
-
(0, redis_lock_decorator_1.UseRedisLock)('hourly-report', { ttl: 3600000 }),
|
|
153
|
-
__metadata("design:type", Function),
|
|
154
|
-
__metadata("design:paramtypes", []),
|
|
155
|
-
__metadata("design:returntype", Promise)
|
|
156
|
-
], ExampleService.prototype, "generateHourlyReport", null);
|
|
157
|
-
exports.ExampleService = ExampleService = ExampleService_1 = __decorate([
|
|
158
|
-
(0, common_1.Injectable)()
|
|
159
|
-
], ExampleService);
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export declare class SchedulerExamples {
|
|
2
|
-
dailyBasicTask(): Promise<void>;
|
|
3
|
-
sixHourlyTaskWithLock(): Promise<void>;
|
|
4
|
-
twoHourlyTaskWithOptions(): Promise<void>;
|
|
5
|
-
hourlySmartTask(): Promise<void>;
|
|
6
|
-
nightlySmartTask(): Promise<void>;
|
|
7
|
-
weeklyReportTask(): Promise<void>;
|
|
8
|
-
monthlyReportTask(): Promise<void>;
|
|
9
|
-
checkStatusWithLock(): Promise<void>;
|
|
10
|
-
checkStatusWithOptions(): Promise<void>;
|
|
11
|
-
checkStatusSmart(): Promise<void>;
|
|
12
|
-
syncDataSmart(): Promise<void>;
|
|
13
|
-
initializeWithLock(): Promise<void>;
|
|
14
|
-
warmUpWithOptions(): Promise<void>;
|
|
15
|
-
weekdayTask(): Promise<void>;
|
|
16
|
-
processDataWithRetry(): Promise<void>;
|
|
17
|
-
private performDataProcessing;
|
|
18
|
-
}
|
|
@@ -1,255 +0,0 @@
|
|
|
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.SchedulerExamples = void 0;
|
|
22
|
-
const common_1 = require("@nestjs/common");
|
|
23
|
-
const schedule_decorator_1 = require("./schedule.decorator");
|
|
24
|
-
let SchedulerExamples = class SchedulerExamples {
|
|
25
|
-
dailyBasicTask() {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
console.log('执行基本定时任务');
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
sixHourlyTaskWithLock() {
|
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
console.log('执行带锁的定时任务');
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
twoHourlyTaskWithOptions() {
|
|
36
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
console.log('执行带选项的定时任务');
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
hourlySmartTask() {
|
|
41
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
console.log('执行智能定时任务');
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
nightlySmartTask() {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
console.log('执行夜间智能定时任务');
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
weeklyReportTask() {
|
|
51
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
console.log('生成周报');
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
monthlyReportTask() {
|
|
56
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
console.log('生成月报');
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
checkStatusWithLock() {
|
|
61
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
console.log('检查系统状态');
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
checkStatusWithOptions() {
|
|
66
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
console.log('检查系统状态(带选项)');
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
checkStatusSmart() {
|
|
71
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
console.log('智能检查系统状态');
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
syncDataSmart() {
|
|
76
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
console.log('智能同步数据');
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
initializeWithLock() {
|
|
81
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
-
console.log('初始化系统');
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
warmUpWithOptions() {
|
|
86
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
console.log('系统预热');
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
weekdayTask() {
|
|
91
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
-
console.log('执行工作日任务');
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
processDataWithRetry() {
|
|
96
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
console.log('开始处理数据');
|
|
98
|
-
try {
|
|
99
|
-
yield this.performDataProcessing();
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
console.error('数据处理失败:', error);
|
|
103
|
-
throw error;
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
performDataProcessing() {
|
|
108
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
-
console.log('数据处理完成');
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
exports.SchedulerExamples = SchedulerExamples;
|
|
114
|
-
__decorate([
|
|
115
|
-
(0, schedule_decorator_1.WorkerCron)('0 0 * * *'),
|
|
116
|
-
__metadata("design:type", Function),
|
|
117
|
-
__metadata("design:paramtypes", []),
|
|
118
|
-
__metadata("design:returntype", Promise)
|
|
119
|
-
], SchedulerExamples.prototype, "dailyBasicTask", null);
|
|
120
|
-
__decorate([
|
|
121
|
-
(0, schedule_decorator_1.WorkerCronWithLock)('0 */6 * * *', 'six-hourly-task', 3600000),
|
|
122
|
-
__metadata("design:type", Function),
|
|
123
|
-
__metadata("design:paramtypes", []),
|
|
124
|
-
__metadata("design:returntype", Promise)
|
|
125
|
-
], SchedulerExamples.prototype, "sixHourlyTaskWithLock", null);
|
|
126
|
-
__decorate([
|
|
127
|
-
(0, schedule_decorator_1.WorkerCronWithLock)('0 */2 * * *', {
|
|
128
|
-
lockTtl: 5400000,
|
|
129
|
-
logExecution: true,
|
|
130
|
-
onError: (error) => console.error('任务执行失败:', error),
|
|
131
|
-
}),
|
|
132
|
-
__metadata("design:type", Function),
|
|
133
|
-
__metadata("design:paramtypes", []),
|
|
134
|
-
__metadata("design:returntype", Promise)
|
|
135
|
-
], SchedulerExamples.prototype, "twoHourlyTaskWithOptions", null);
|
|
136
|
-
__decorate([
|
|
137
|
-
(0, schedule_decorator_1.WorkerCronSmart)('0 * * * *'),
|
|
138
|
-
__metadata("design:type", Function),
|
|
139
|
-
__metadata("design:paramtypes", []),
|
|
140
|
-
__metadata("design:returntype", Promise)
|
|
141
|
-
], SchedulerExamples.prototype, "hourlySmartTask", null);
|
|
142
|
-
__decorate([
|
|
143
|
-
(0, schedule_decorator_1.WorkerCronSmart)('30 2 * * *', {
|
|
144
|
-
lockTtl: 3600000,
|
|
145
|
-
logExecution: true,
|
|
146
|
-
onError: (error) => console.error('夜间任务失败:', error),
|
|
147
|
-
onSuccess: (duration) => console.log(`夜间任务完成,耗时: ${duration}ms`),
|
|
148
|
-
}),
|
|
149
|
-
__metadata("design:type", Function),
|
|
150
|
-
__metadata("design:paramtypes", []),
|
|
151
|
-
__metadata("design:returntype", Promise)
|
|
152
|
-
], SchedulerExamples.prototype, "nightlySmartTask", null);
|
|
153
|
-
__decorate([
|
|
154
|
-
(0, schedule_decorator_1.WorkerCronAdvanced)('0 0 * * 0', 'weekly-report', {
|
|
155
|
-
lockTtl: 7200000,
|
|
156
|
-
logExecution: true,
|
|
157
|
-
onError: (error) => console.error('周报生成失败:', error),
|
|
158
|
-
}),
|
|
159
|
-
__metadata("design:type", Function),
|
|
160
|
-
__metadata("design:paramtypes", []),
|
|
161
|
-
__metadata("design:returntype", Promise)
|
|
162
|
-
], SchedulerExamples.prototype, "weeklyReportTask", null);
|
|
163
|
-
__decorate([
|
|
164
|
-
(0, schedule_decorator_1.WorkerCronAdvanced)('0 0 1 * *', {
|
|
165
|
-
lockTtl: 14400000,
|
|
166
|
-
logExecution: true,
|
|
167
|
-
onError: (error) => console.error('月报生成失败:', error),
|
|
168
|
-
onSuccess: (duration) => console.log(`月报生成完成,耗时: ${duration}ms`),
|
|
169
|
-
}),
|
|
170
|
-
__metadata("design:type", Function),
|
|
171
|
-
__metadata("design:paramtypes", []),
|
|
172
|
-
__metadata("design:returntype", Promise)
|
|
173
|
-
], SchedulerExamples.prototype, "monthlyReportTask", null);
|
|
174
|
-
__decorate([
|
|
175
|
-
(0, schedule_decorator_1.WorkerIntervalWithLock)(60000, 'status-check'),
|
|
176
|
-
__metadata("design:type", Function),
|
|
177
|
-
__metadata("design:paramtypes", []),
|
|
178
|
-
__metadata("design:returntype", Promise)
|
|
179
|
-
], SchedulerExamples.prototype, "checkStatusWithLock", null);
|
|
180
|
-
__decorate([
|
|
181
|
-
(0, schedule_decorator_1.WorkerIntervalWithLock)(300000, {
|
|
182
|
-
lockTtl: 240000,
|
|
183
|
-
logExecution: true,
|
|
184
|
-
onError: (error) => console.error('状态检查失败:', error),
|
|
185
|
-
}),
|
|
186
|
-
__metadata("design:type", Function),
|
|
187
|
-
__metadata("design:paramtypes", []),
|
|
188
|
-
__metadata("design:returntype", Promise)
|
|
189
|
-
], SchedulerExamples.prototype, "checkStatusWithOptions", null);
|
|
190
|
-
__decorate([
|
|
191
|
-
(0, schedule_decorator_1.WorkerIntervalSmart)(120000),
|
|
192
|
-
__metadata("design:type", Function),
|
|
193
|
-
__metadata("design:paramtypes", []),
|
|
194
|
-
__metadata("design:returntype", Promise)
|
|
195
|
-
], SchedulerExamples.prototype, "checkStatusSmart", null);
|
|
196
|
-
__decorate([
|
|
197
|
-
(0, schedule_decorator_1.WorkerIntervalSmart)(600000, {
|
|
198
|
-
lockTtl: 480000,
|
|
199
|
-
logExecution: true,
|
|
200
|
-
onError: (error) => console.error('数据同步失败:', error),
|
|
201
|
-
onSuccess: (duration) => console.log(`数据同步完成,耗时: ${duration}ms`),
|
|
202
|
-
}),
|
|
203
|
-
__metadata("design:type", Function),
|
|
204
|
-
__metadata("design:paramtypes", []),
|
|
205
|
-
__metadata("design:returntype", Promise)
|
|
206
|
-
], SchedulerExamples.prototype, "syncDataSmart", null);
|
|
207
|
-
__decorate([
|
|
208
|
-
(0, schedule_decorator_1.WorkerTimeoutWithLock)(5000, 'init-task', 10000),
|
|
209
|
-
__metadata("design:type", Function),
|
|
210
|
-
__metadata("design:paramtypes", []),
|
|
211
|
-
__metadata("design:returntype", Promise)
|
|
212
|
-
], SchedulerExamples.prototype, "initializeWithLock", null);
|
|
213
|
-
__decorate([
|
|
214
|
-
(0, schedule_decorator_1.WorkerTimeoutWithLock)(10000, {
|
|
215
|
-
lockTtl: 30000,
|
|
216
|
-
logExecution: true,
|
|
217
|
-
onError: (error) => console.error('预热任务失败:', error),
|
|
218
|
-
}),
|
|
219
|
-
__metadata("design:type", Function),
|
|
220
|
-
__metadata("design:paramtypes", []),
|
|
221
|
-
__metadata("design:returntype", Promise)
|
|
222
|
-
], SchedulerExamples.prototype, "warmUpWithOptions", null);
|
|
223
|
-
__decorate([
|
|
224
|
-
(0, schedule_decorator_1.WorkerCronSmart)('0 9 * * 1-5', {
|
|
225
|
-
lockTtl: 3600000,
|
|
226
|
-
logExecution: true,
|
|
227
|
-
onError: (error) => console.error('工作日任务失败:', error),
|
|
228
|
-
onSuccess: (duration) => {
|
|
229
|
-
console.log(`工作日任务完成,耗时: ${duration}ms`);
|
|
230
|
-
},
|
|
231
|
-
}),
|
|
232
|
-
__metadata("design:type", Function),
|
|
233
|
-
__metadata("design:paramtypes", []),
|
|
234
|
-
__metadata("design:returntype", Promise)
|
|
235
|
-
], SchedulerExamples.prototype, "weekdayTask", null);
|
|
236
|
-
__decorate([
|
|
237
|
-
(0, schedule_decorator_1.WorkerCronSmart)('0 */30 * * * *', {
|
|
238
|
-
lockTtl: 1500000,
|
|
239
|
-
logExecution: true,
|
|
240
|
-
onError: (error) => __awaiter(void 0, void 0, void 0, function* () {
|
|
241
|
-
console.error('数据处理任务失败:', error);
|
|
242
|
-
}),
|
|
243
|
-
onSuccess: (duration) => {
|
|
244
|
-
if (duration > 60000) {
|
|
245
|
-
console.warn(`数据处理任务耗时较长: ${duration}ms`);
|
|
246
|
-
}
|
|
247
|
-
},
|
|
248
|
-
}),
|
|
249
|
-
__metadata("design:type", Function),
|
|
250
|
-
__metadata("design:paramtypes", []),
|
|
251
|
-
__metadata("design:returntype", Promise)
|
|
252
|
-
], SchedulerExamples.prototype, "processDataWithRetry", null);
|
|
253
|
-
exports.SchedulerExamples = SchedulerExamples = __decorate([
|
|
254
|
-
(0, common_1.Injectable)()
|
|
255
|
-
], SchedulerExamples);
|