@punks/backend-entity-manager 0.0.365 → 0.0.367
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +305 -96
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/abstractions/index.d.ts +1 -0
- package/dist/cjs/types/abstractions/serializer.d.ts +2 -0
- package/dist/cjs/types/abstractions/tasks.d.ts +13 -0
- package/dist/cjs/types/platforms/nest/__test__/tests/tasks/parallel-task.test.d.ts +1 -0
- package/dist/cjs/types/platforms/nest/__test__/tests/tasks/single-task.test.d.ts +1 -0
- package/dist/cjs/types/platforms/nest/__test__/tests/tasks/tasks.d.ts +12 -0
- package/dist/cjs/types/platforms/nest/decorators/index.d.ts +1 -0
- package/dist/cjs/types/platforms/nest/decorators/tasks.d.ts +13 -0
- package/dist/cjs/types/platforms/nest/extensions/index.d.ts +1 -0
- package/dist/cjs/types/platforms/nest/extensions/tasks/index.d.ts +1 -0
- package/dist/cjs/types/platforms/nest/extensions/tasks/initializer.d.ts +13 -0
- package/dist/cjs/types/platforms/nest/extensions/tasks/module.d.ts +7 -0
- package/dist/cjs/types/platforms/nest/extensions/tasks/task-scheduler/index.d.ts +13 -0
- package/dist/cjs/types/platforms/nest/extensions/tasks/task-shell/index.d.ts +15 -0
- package/dist/cjs/types/utils/cron.d.ts +1 -0
- package/dist/cjs/types/utils/dates.d.ts +1 -0
- package/dist/esm/index.js +305 -97
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/abstractions/index.d.ts +1 -0
- package/dist/esm/types/abstractions/serializer.d.ts +2 -0
- package/dist/esm/types/abstractions/tasks.d.ts +13 -0
- package/dist/esm/types/platforms/nest/__test__/tests/tasks/parallel-task.test.d.ts +1 -0
- package/dist/esm/types/platforms/nest/__test__/tests/tasks/single-task.test.d.ts +1 -0
- package/dist/esm/types/platforms/nest/__test__/tests/tasks/tasks.d.ts +12 -0
- package/dist/esm/types/platforms/nest/decorators/index.d.ts +1 -0
- package/dist/esm/types/platforms/nest/decorators/tasks.d.ts +13 -0
- package/dist/esm/types/platforms/nest/extensions/index.d.ts +1 -0
- package/dist/esm/types/platforms/nest/extensions/tasks/index.d.ts +1 -0
- package/dist/esm/types/platforms/nest/extensions/tasks/initializer.d.ts +13 -0
- package/dist/esm/types/platforms/nest/extensions/tasks/module.d.ts +7 -0
- package/dist/esm/types/platforms/nest/extensions/tasks/task-scheduler/index.d.ts +13 -0
- package/dist/esm/types/platforms/nest/extensions/tasks/task-shell/index.d.ts +15 -0
- package/dist/esm/types/utils/cron.d.ts +1 -0
- package/dist/esm/types/utils/dates.d.ts +1 -0
- package/dist/index.d.ts +60 -2
- package/package.json +16 -16
package/dist/esm/index.js
CHANGED
|
@@ -216,8 +216,10 @@ class EntitySerializer {
|
|
|
216
216
|
return records.map((x, i) => this.convertSheetRecord(x, definition, i));
|
|
217
217
|
}
|
|
218
218
|
parseXlsx(data, definition) {
|
|
219
|
+
const dateColumns = definition.columns.filter((x) => x.sheetParser === "date");
|
|
219
220
|
const records = excelParse(data, {
|
|
220
221
|
keysTransform: ExcelKeyTransform.Lower,
|
|
222
|
+
dateColumns: dateColumns.map((x) => x.name),
|
|
221
223
|
});
|
|
222
224
|
return records.map((x, i) => this.convertSheetRecord(x, definition, i));
|
|
223
225
|
}
|
|
@@ -4245,6 +4247,19 @@ const WpEntitySnapshotService = (entityName, props = {}) => applyDecorators(Inje
|
|
|
4245
4247
|
...props,
|
|
4246
4248
|
}));
|
|
4247
4249
|
|
|
4250
|
+
const TASK_KEY = "wp_task";
|
|
4251
|
+
var TaskConcurrency;
|
|
4252
|
+
(function (TaskConcurrency) {
|
|
4253
|
+
TaskConcurrency["Single"] = "single";
|
|
4254
|
+
TaskConcurrency["Multiple"] = "multiple";
|
|
4255
|
+
})(TaskConcurrency || (TaskConcurrency = {}));
|
|
4256
|
+
function WpTask(name, settings) {
|
|
4257
|
+
return applyDecorators(Injectable(), SetMetadata(TASK_KEY, {
|
|
4258
|
+
name,
|
|
4259
|
+
...settings,
|
|
4260
|
+
}));
|
|
4261
|
+
}
|
|
4262
|
+
|
|
4248
4263
|
const WpEventsTracker = (props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EventsTracker, {
|
|
4249
4264
|
...props,
|
|
4250
4265
|
}));
|
|
@@ -22220,26 +22235,6 @@ MediaLibraryService = __decorate([
|
|
|
22220
22235
|
__metadata("design:paramtypes", [EntityManagerRegistry])
|
|
22221
22236
|
], MediaLibraryService);
|
|
22222
22237
|
|
|
22223
|
-
function toInteger(dirtyNumber) {
|
|
22224
|
-
if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
|
|
22225
|
-
return NaN;
|
|
22226
|
-
}
|
|
22227
|
-
|
|
22228
|
-
var number = Number(dirtyNumber);
|
|
22229
|
-
|
|
22230
|
-
if (isNaN(number)) {
|
|
22231
|
-
return number;
|
|
22232
|
-
}
|
|
22233
|
-
|
|
22234
|
-
return number < 0 ? Math.ceil(number) : Math.floor(number);
|
|
22235
|
-
}
|
|
22236
|
-
|
|
22237
|
-
function requiredArgs(required, args) {
|
|
22238
|
-
if (args.length < required) {
|
|
22239
|
-
throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present');
|
|
22240
|
-
}
|
|
22241
|
-
}
|
|
22242
|
-
|
|
22243
22238
|
/**
|
|
22244
22239
|
* @name toDate
|
|
22245
22240
|
* @category Common Helpers
|
|
@@ -22256,9 +22251,11 @@ function requiredArgs(required, args) {
|
|
|
22256
22251
|
*
|
|
22257
22252
|
* **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
|
|
22258
22253
|
*
|
|
22259
|
-
* @
|
|
22260
|
-
*
|
|
22261
|
-
* @
|
|
22254
|
+
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
22255
|
+
*
|
|
22256
|
+
* @param argument - The value to convert
|
|
22257
|
+
*
|
|
22258
|
+
* @returns The parsed date in the local time zone
|
|
22262
22259
|
*
|
|
22263
22260
|
* @example
|
|
22264
22261
|
* // Clone the date:
|
|
@@ -22270,28 +22267,68 @@ function requiredArgs(required, args) {
|
|
|
22270
22267
|
* const result = toDate(1392098430000)
|
|
22271
22268
|
* //=> Tue Feb 11 2014 11:30:30
|
|
22272
22269
|
*/
|
|
22273
|
-
|
|
22274
22270
|
function toDate(argument) {
|
|
22275
|
-
|
|
22276
|
-
var argStr = Object.prototype.toString.call(argument); // Clone the date
|
|
22271
|
+
const argStr = Object.prototype.toString.call(argument);
|
|
22277
22272
|
|
|
22278
|
-
|
|
22273
|
+
// Clone the date
|
|
22274
|
+
if (
|
|
22275
|
+
argument instanceof Date ||
|
|
22276
|
+
(typeof argument === "object" && argStr === "[object Date]")
|
|
22277
|
+
) {
|
|
22279
22278
|
// Prevent the date to lose the milliseconds when passed to new Date() in IE10
|
|
22280
|
-
return new
|
|
22281
|
-
} else if (
|
|
22279
|
+
return new argument.constructor(+argument);
|
|
22280
|
+
} else if (
|
|
22281
|
+
typeof argument === "number" ||
|
|
22282
|
+
argStr === "[object Number]" ||
|
|
22283
|
+
typeof argument === "string" ||
|
|
22284
|
+
argStr === "[object String]"
|
|
22285
|
+
) {
|
|
22286
|
+
// TODO: Can we get rid of as?
|
|
22282
22287
|
return new Date(argument);
|
|
22283
22288
|
} else {
|
|
22284
|
-
|
|
22285
|
-
// eslint-disable-next-line no-console
|
|
22286
|
-
console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://git.io/fjule"); // eslint-disable-next-line no-console
|
|
22287
|
-
|
|
22288
|
-
console.warn(new Error().stack);
|
|
22289
|
-
}
|
|
22290
|
-
|
|
22289
|
+
// TODO: Can we get rid of as?
|
|
22291
22290
|
return new Date(NaN);
|
|
22292
22291
|
}
|
|
22293
22292
|
}
|
|
22294
22293
|
|
|
22294
|
+
/**
|
|
22295
|
+
* @name constructFrom
|
|
22296
|
+
* @category Generic Helpers
|
|
22297
|
+
* @summary Constructs a date using the reference date and the value
|
|
22298
|
+
*
|
|
22299
|
+
* @description
|
|
22300
|
+
* The function constructs a new date using the constructor from the reference
|
|
22301
|
+
* date and the given value. It helps to build generic functions that accept
|
|
22302
|
+
* date extensions.
|
|
22303
|
+
*
|
|
22304
|
+
* It defaults to `Date` if the passed reference date is a number or a string.
|
|
22305
|
+
*
|
|
22306
|
+
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
22307
|
+
*
|
|
22308
|
+
* @param date - The reference date to take constructor from
|
|
22309
|
+
* @param value - The value to create the date
|
|
22310
|
+
*
|
|
22311
|
+
* @returns Date initialized using the given date and value
|
|
22312
|
+
*
|
|
22313
|
+
* @example
|
|
22314
|
+
* import { constructFrom } from 'date-fns'
|
|
22315
|
+
*
|
|
22316
|
+
* // A function that clones a date preserving the original type
|
|
22317
|
+
* function cloneDate<DateType extends Date(date: DateType): DateType {
|
|
22318
|
+
* return constructFrom(
|
|
22319
|
+
* date, // Use contrustor from the given date
|
|
22320
|
+
* date.getTime() // Use the date value to create a new date
|
|
22321
|
+
* )
|
|
22322
|
+
* }
|
|
22323
|
+
*/
|
|
22324
|
+
function constructFrom(date, value) {
|
|
22325
|
+
if (date instanceof Date) {
|
|
22326
|
+
return new date.constructor(value);
|
|
22327
|
+
} else {
|
|
22328
|
+
return new Date(value);
|
|
22329
|
+
}
|
|
22330
|
+
}
|
|
22331
|
+
|
|
22295
22332
|
/**
|
|
22296
22333
|
* @name addDays
|
|
22297
22334
|
* @category Day Helpers
|
|
@@ -22300,37 +22337,60 @@ function toDate(argument) {
|
|
|
22300
22337
|
* @description
|
|
22301
22338
|
* Add the specified number of days to the given date.
|
|
22302
22339
|
*
|
|
22303
|
-
*
|
|
22340
|
+
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
22304
22341
|
*
|
|
22305
|
-
*
|
|
22342
|
+
* @param date - The date to be changed
|
|
22343
|
+
* @param amount - The amount of days to be added.
|
|
22306
22344
|
*
|
|
22307
|
-
* @
|
|
22308
|
-
* @param {Number} amount - the amount of days to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
|
|
22309
|
-
* @returns {Date} the new date with the days added
|
|
22310
|
-
* @throws {TypeError} 2 arguments required
|
|
22345
|
+
* @returns The new date with the days added
|
|
22311
22346
|
*
|
|
22312
22347
|
* @example
|
|
22313
22348
|
* // Add 10 days to 1 September 2014:
|
|
22314
|
-
*
|
|
22349
|
+
* const result = addDays(new Date(2014, 8, 1), 10)
|
|
22315
22350
|
* //=> Thu Sep 11 2014 00:00:00
|
|
22316
22351
|
*/
|
|
22317
|
-
|
|
22318
|
-
|
|
22319
|
-
|
|
22320
|
-
var date = toDate(dirtyDate);
|
|
22321
|
-
var amount = toInteger(dirtyAmount);
|
|
22322
|
-
|
|
22323
|
-
if (isNaN(amount)) {
|
|
22324
|
-
return new Date(NaN);
|
|
22325
|
-
}
|
|
22326
|
-
|
|
22352
|
+
function addDays(date, amount) {
|
|
22353
|
+
const _date = toDate(date);
|
|
22354
|
+
if (isNaN(amount)) return constructFrom(date, NaN);
|
|
22327
22355
|
if (!amount) {
|
|
22328
22356
|
// If 0 days, no-op to avoid changing times in the hour before end of DST
|
|
22329
|
-
return
|
|
22357
|
+
return _date;
|
|
22330
22358
|
}
|
|
22359
|
+
_date.setDate(_date.getDate() + amount);
|
|
22360
|
+
return _date;
|
|
22361
|
+
}
|
|
22331
22362
|
|
|
22332
|
-
|
|
22333
|
-
|
|
22363
|
+
/**
|
|
22364
|
+
* @module constants
|
|
22365
|
+
* @summary Useful constants
|
|
22366
|
+
* @description
|
|
22367
|
+
* Collection of useful date constants.
|
|
22368
|
+
*
|
|
22369
|
+
* The constants could be imported from `date-fns/constants`:
|
|
22370
|
+
*
|
|
22371
|
+
* ```ts
|
|
22372
|
+
* import { maxTime, minTime } from "./constants/date-fns/constants";
|
|
22373
|
+
*
|
|
22374
|
+
* function isAllowedTime(time) {
|
|
22375
|
+
* return time <= maxTime && time >= minTime;
|
|
22376
|
+
* }
|
|
22377
|
+
* ```
|
|
22378
|
+
*/
|
|
22379
|
+
|
|
22380
|
+
/**
|
|
22381
|
+
* @constant
|
|
22382
|
+
* @name millisecondsInMinute
|
|
22383
|
+
* @summary Milliseconds in 1 minute
|
|
22384
|
+
*/
|
|
22385
|
+
const millisecondsInMinute = 60000;
|
|
22386
|
+
|
|
22387
|
+
function getRoundingMethod(method) {
|
|
22388
|
+
return (number) => {
|
|
22389
|
+
const round = method ? Math[method] : Math.trunc;
|
|
22390
|
+
const result = round(number);
|
|
22391
|
+
// Prevent negative zero
|
|
22392
|
+
return result === 0 ? 0 : result;
|
|
22393
|
+
};
|
|
22334
22394
|
}
|
|
22335
22395
|
|
|
22336
22396
|
/**
|
|
@@ -22341,33 +22401,30 @@ function addDays(dirtyDate, dirtyAmount) {
|
|
|
22341
22401
|
* @description
|
|
22342
22402
|
* Get the number of milliseconds between the given dates.
|
|
22343
22403
|
*
|
|
22344
|
-
*
|
|
22404
|
+
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
22345
22405
|
*
|
|
22346
|
-
*
|
|
22406
|
+
* @param dateLeft - The later date
|
|
22407
|
+
* @param dateRight - The earlier date
|
|
22347
22408
|
*
|
|
22348
|
-
* @
|
|
22349
|
-
* @param {Date|Number} dateRight - the earlier date
|
|
22350
|
-
* @returns {Number} the number of milliseconds
|
|
22351
|
-
* @throws {TypeError} 2 arguments required
|
|
22409
|
+
* @returns The number of milliseconds
|
|
22352
22410
|
*
|
|
22353
22411
|
* @example
|
|
22354
22412
|
* // How many milliseconds are between
|
|
22355
22413
|
* // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?
|
|
22356
|
-
*
|
|
22414
|
+
* const result = differenceInMilliseconds(
|
|
22357
22415
|
* new Date(2014, 6, 2, 12, 30, 21, 700),
|
|
22358
22416
|
* new Date(2014, 6, 2, 12, 30, 20, 600)
|
|
22359
22417
|
* )
|
|
22360
22418
|
* //=> 1100
|
|
22361
22419
|
*/
|
|
22362
|
-
|
|
22363
|
-
|
|
22364
|
-
requiredArgs(2, arguments);
|
|
22365
|
-
var dateLeft = toDate(dirtyDateLeft);
|
|
22366
|
-
var dateRight = toDate(dirtyDateRight);
|
|
22367
|
-
return dateLeft.getTime() - dateRight.getTime();
|
|
22420
|
+
function differenceInMilliseconds(dateLeft, dateRight) {
|
|
22421
|
+
return +toDate(dateLeft) - +toDate(dateRight);
|
|
22368
22422
|
}
|
|
22369
22423
|
|
|
22370
|
-
|
|
22424
|
+
/**
|
|
22425
|
+
* The {@link differenceInMinutes} function options.
|
|
22426
|
+
*/
|
|
22427
|
+
|
|
22371
22428
|
/**
|
|
22372
22429
|
* @name differenceInMinutes
|
|
22373
22430
|
* @category Minute Helpers
|
|
@@ -22376,36 +22433,34 @@ var MILLISECONDS_IN_MINUTE = 60000;
|
|
|
22376
22433
|
* @description
|
|
22377
22434
|
* Get the signed number of full (rounded towards 0) minutes between the given dates.
|
|
22378
22435
|
*
|
|
22379
|
-
*
|
|
22436
|
+
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
22380
22437
|
*
|
|
22381
|
-
*
|
|
22438
|
+
* @param dateLeft - The later date
|
|
22439
|
+
* @param dateRight - The earlier date
|
|
22440
|
+
* @param options - An object with options.
|
|
22382
22441
|
*
|
|
22383
|
-
* @
|
|
22384
|
-
* @param {Date|Number} dateRight - the earlier date
|
|
22385
|
-
* @returns {Number} the number of minutes
|
|
22386
|
-
* @throws {TypeError} 2 arguments required
|
|
22442
|
+
* @returns The number of minutes
|
|
22387
22443
|
*
|
|
22388
22444
|
* @example
|
|
22389
22445
|
* // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
|
|
22390
|
-
*
|
|
22446
|
+
* const result = differenceInMinutes(
|
|
22391
22447
|
* new Date(2014, 6, 2, 12, 20, 0),
|
|
22392
22448
|
* new Date(2014, 6, 2, 12, 7, 59)
|
|
22393
22449
|
* )
|
|
22394
22450
|
* //=> 12
|
|
22395
22451
|
*
|
|
22396
22452
|
* @example
|
|
22397
|
-
* // How many minutes are
|
|
22398
|
-
*
|
|
22453
|
+
* // How many minutes are between 10:01:59 and 10:00:00
|
|
22454
|
+
* const result = differenceInMinutes(
|
|
22399
22455
|
* new Date(2000, 0, 1, 10, 0, 0),
|
|
22400
22456
|
* new Date(2000, 0, 1, 10, 1, 59)
|
|
22401
22457
|
* )
|
|
22402
22458
|
* //=> -1
|
|
22403
22459
|
*/
|
|
22404
|
-
|
|
22405
|
-
|
|
22406
|
-
|
|
22407
|
-
|
|
22408
|
-
return diff > 0 ? Math.floor(diff) : Math.ceil(diff);
|
|
22460
|
+
function differenceInMinutes(dateLeft, dateRight, options) {
|
|
22461
|
+
const diff =
|
|
22462
|
+
differenceInMilliseconds(dateLeft, dateRight) / millisecondsInMinute;
|
|
22463
|
+
return getRoundingMethod(options?.roundingMethod)(diff);
|
|
22409
22464
|
}
|
|
22410
22465
|
|
|
22411
22466
|
/**
|
|
@@ -22416,25 +22471,20 @@ function differenceInMinutes(dirtyDateLeft, dirtyDateRight) {
|
|
|
22416
22471
|
* @description
|
|
22417
22472
|
* Subtract the specified number of days from the given date.
|
|
22418
22473
|
*
|
|
22419
|
-
*
|
|
22474
|
+
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
22420
22475
|
*
|
|
22421
|
-
*
|
|
22476
|
+
* @param date - The date to be changed
|
|
22477
|
+
* @param amount - The amount of days to be subtracted.
|
|
22422
22478
|
*
|
|
22423
|
-
* @
|
|
22424
|
-
* @param {Number} amount - the amount of days to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
|
|
22425
|
-
* @returns {Date} the new date with the days subtracted
|
|
22426
|
-
* @throws {TypeError} 2 arguments required
|
|
22479
|
+
* @returns The new date with the days subtracted
|
|
22427
22480
|
*
|
|
22428
22481
|
* @example
|
|
22429
22482
|
* // Subtract 10 days from 1 September 2014:
|
|
22430
|
-
*
|
|
22483
|
+
* const result = subDays(new Date(2014, 8, 1), 10)
|
|
22431
22484
|
* //=> Fri Aug 22 2014 00:00:00
|
|
22432
22485
|
*/
|
|
22433
|
-
|
|
22434
|
-
|
|
22435
|
-
requiredArgs(2, arguments);
|
|
22436
|
-
var amount = toInteger(dirtyAmount);
|
|
22437
|
-
return addDays(dirtyDate, -amount);
|
|
22486
|
+
function subDays(date, amount) {
|
|
22487
|
+
return addDays(date, -amount);
|
|
22438
22488
|
}
|
|
22439
22489
|
|
|
22440
22490
|
const WpOperationLockService = (props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.OperationLockService, {
|
|
@@ -34729,6 +34779,164 @@ JobsModule = JobsModule_1 = __decorate([
|
|
|
34729
34779
|
JobsProviderFactory])
|
|
34730
34780
|
], JobsModule);
|
|
34731
34781
|
|
|
34782
|
+
var TaskRunType;
|
|
34783
|
+
(function (TaskRunType) {
|
|
34784
|
+
TaskRunType["Scheduled"] = "Scheduled";
|
|
34785
|
+
TaskRunType["OnDemand"] = "OnDemand";
|
|
34786
|
+
})(TaskRunType || (TaskRunType = {}));
|
|
34787
|
+
|
|
34788
|
+
const getCronCurrentSchedule = (cronExpression, ref) => {
|
|
34789
|
+
const interval = parser$1.parseExpression(cronExpression, {
|
|
34790
|
+
currentDate: ref,
|
|
34791
|
+
});
|
|
34792
|
+
return interval.prev().toDate();
|
|
34793
|
+
};
|
|
34794
|
+
|
|
34795
|
+
function floorDateToSecond(date) {
|
|
34796
|
+
const flooredDate = new Date(date);
|
|
34797
|
+
flooredDate.setMilliseconds(0);
|
|
34798
|
+
return flooredDate;
|
|
34799
|
+
}
|
|
34800
|
+
|
|
34801
|
+
var TaskShell_1;
|
|
34802
|
+
let TaskShell = TaskShell_1 = class TaskShell {
|
|
34803
|
+
constructor(registry, operations) {
|
|
34804
|
+
this.registry = registry;
|
|
34805
|
+
this.operations = operations;
|
|
34806
|
+
this.logger = Log.getLogger(TaskShell_1.name);
|
|
34807
|
+
}
|
|
34808
|
+
async executeTask(instance, settings) {
|
|
34809
|
+
switch (settings.concurrency) {
|
|
34810
|
+
case TaskConcurrency.Single:
|
|
34811
|
+
return await this.executeTaskSequential(instance, settings);
|
|
34812
|
+
case TaskConcurrency.Multiple:
|
|
34813
|
+
return await this.executeTaskParallel(instance, settings);
|
|
34814
|
+
default:
|
|
34815
|
+
throw new Error(`Unknown task concurrency: ${settings.concurrency}`);
|
|
34816
|
+
}
|
|
34817
|
+
}
|
|
34818
|
+
async executeTaskParallel(instance, settings) {
|
|
34819
|
+
await this.invokeTask(instance, settings);
|
|
34820
|
+
}
|
|
34821
|
+
async executeTaskSequential(instance, settings) {
|
|
34822
|
+
const currentSchedule = getCronCurrentSchedule(settings.cronExpression, new Date());
|
|
34823
|
+
const lockKey = this.getTaskLockKey(settings, currentSchedule);
|
|
34824
|
+
const lock = await this.operations.acquireLock({
|
|
34825
|
+
lockUid: lockKey,
|
|
34826
|
+
});
|
|
34827
|
+
if (lock.available) {
|
|
34828
|
+
await this.invokeTask(instance, settings);
|
|
34829
|
+
}
|
|
34830
|
+
}
|
|
34831
|
+
getTaskLockKey(settings, cronSchedule) {
|
|
34832
|
+
return `task:${settings.name}:${floorDateToSecond(cronSchedule).toISOString()}`;
|
|
34833
|
+
}
|
|
34834
|
+
async invokeTask(instance, settings) {
|
|
34835
|
+
try {
|
|
34836
|
+
this.logger.info(`Task ${settings.name} -> starting`);
|
|
34837
|
+
await instance.execute({
|
|
34838
|
+
name: settings.name,
|
|
34839
|
+
startedAt: new Date(),
|
|
34840
|
+
runId: newUuid$1(),
|
|
34841
|
+
runType: TaskRunType.Scheduled,
|
|
34842
|
+
});
|
|
34843
|
+
this.logger.info(`Task ${settings.name} -> completed`);
|
|
34844
|
+
}
|
|
34845
|
+
catch (error) {
|
|
34846
|
+
this.logger.exception(`Task ${settings.name} -> failed`, error);
|
|
34847
|
+
}
|
|
34848
|
+
}
|
|
34849
|
+
get operationsLockService() {
|
|
34850
|
+
return this.registry
|
|
34851
|
+
.getContainer()
|
|
34852
|
+
.getEntitiesServicesLocator()
|
|
34853
|
+
.resolveOperationLockService();
|
|
34854
|
+
}
|
|
34855
|
+
};
|
|
34856
|
+
TaskShell = TaskShell_1 = __decorate([
|
|
34857
|
+
Injectable(),
|
|
34858
|
+
__param(1, Inject(getEntityManagerProviderToken("OperationsLockRepository"))),
|
|
34859
|
+
__metadata("design:paramtypes", [EntityManagerRegistry, Object])
|
|
34860
|
+
], TaskShell);
|
|
34861
|
+
|
|
34862
|
+
var TaskScheduler_1;
|
|
34863
|
+
let TaskScheduler = TaskScheduler_1 = class TaskScheduler {
|
|
34864
|
+
constructor(schedulerRegistry, jobShell) {
|
|
34865
|
+
this.schedulerRegistry = schedulerRegistry;
|
|
34866
|
+
this.jobShell = jobShell;
|
|
34867
|
+
this.logger = new Logger(TaskScheduler_1.name);
|
|
34868
|
+
this.jobs = [];
|
|
34869
|
+
}
|
|
34870
|
+
async registerTask(job, instance) {
|
|
34871
|
+
const cronJob = new dist.CronJob(job.cronExpression, async (context) => {
|
|
34872
|
+
await this.jobShell.executeTask(instance, job);
|
|
34873
|
+
});
|
|
34874
|
+
this.schedulerRegistry.addCronJob(job.name, cronJob);
|
|
34875
|
+
cronJob.start();
|
|
34876
|
+
this.jobs.push(cronJob);
|
|
34877
|
+
this.logger.log(`Jobs ${job.name} registered`);
|
|
34878
|
+
}
|
|
34879
|
+
stopAllTasks() {
|
|
34880
|
+
this.jobs.forEach((job) => {
|
|
34881
|
+
job.stop();
|
|
34882
|
+
});
|
|
34883
|
+
}
|
|
34884
|
+
};
|
|
34885
|
+
TaskScheduler = TaskScheduler_1 = __decorate([
|
|
34886
|
+
Injectable(),
|
|
34887
|
+
__metadata("design:paramtypes", [SchedulerRegistry,
|
|
34888
|
+
TaskShell])
|
|
34889
|
+
], TaskScheduler);
|
|
34890
|
+
|
|
34891
|
+
var TasksInitializer_1;
|
|
34892
|
+
let TasksInitializer = TasksInitializer_1 = class TasksInitializer {
|
|
34893
|
+
constructor(discover, scheduler) {
|
|
34894
|
+
this.discover = discover;
|
|
34895
|
+
this.scheduler = scheduler;
|
|
34896
|
+
this.logger = new Logger(TasksInitializer_1.name);
|
|
34897
|
+
}
|
|
34898
|
+
async initialize(app) {
|
|
34899
|
+
await this.registerCronJobs();
|
|
34900
|
+
this.logger.log("Tasks initialized 🎰");
|
|
34901
|
+
}
|
|
34902
|
+
async registerCronJobs() {
|
|
34903
|
+
const tasks = await this.discoverTasks();
|
|
34904
|
+
const duplicatedJobs = tasks.filter((job, index, self) => index !== self.findIndex((t) => t.meta.name === job.meta.name));
|
|
34905
|
+
if (duplicatedJobs.length) {
|
|
34906
|
+
throw new Error(`Duplicated jobs found: ${duplicatedJobs
|
|
34907
|
+
.map((j) => j.meta.name)
|
|
34908
|
+
.join(", ")}`);
|
|
34909
|
+
}
|
|
34910
|
+
for (const task of tasks) {
|
|
34911
|
+
await this.scheduler.registerTask(task.meta, task.discoveredClass.instance);
|
|
34912
|
+
}
|
|
34913
|
+
}
|
|
34914
|
+
async discoverTasks() {
|
|
34915
|
+
return await this.discover.providersWithMetaAtKey(TASK_KEY);
|
|
34916
|
+
}
|
|
34917
|
+
};
|
|
34918
|
+
TasksInitializer = TasksInitializer_1 = __decorate([
|
|
34919
|
+
WpAppInitializer(),
|
|
34920
|
+
__metadata("design:paramtypes", [CustomDiscoveryService,
|
|
34921
|
+
TaskScheduler])
|
|
34922
|
+
], TasksInitializer);
|
|
34923
|
+
|
|
34924
|
+
let TasksModule = class TasksModule {
|
|
34925
|
+
constructor(scheduler) {
|
|
34926
|
+
this.scheduler = scheduler;
|
|
34927
|
+
}
|
|
34928
|
+
onModuleDestroy() {
|
|
34929
|
+
this.scheduler.stopAllTasks();
|
|
34930
|
+
}
|
|
34931
|
+
};
|
|
34932
|
+
TasksModule = __decorate([
|
|
34933
|
+
Module({
|
|
34934
|
+
imports: [EntityManagerModule],
|
|
34935
|
+
providers: [TasksInitializer, TaskScheduler, TaskShell],
|
|
34936
|
+
}),
|
|
34937
|
+
__metadata("design:paramtypes", [TaskScheduler])
|
|
34938
|
+
], TasksModule);
|
|
34939
|
+
|
|
34732
34940
|
const createExpressFileResponse = (res, file) => {
|
|
34733
34941
|
res.set({
|
|
34734
34942
|
"Content-Type": file.contentType,
|
|
@@ -44410,5 +44618,5 @@ class TestingAppSessionService {
|
|
|
44410
44618
|
}
|
|
44411
44619
|
}
|
|
44412
44620
|
|
|
44413
|
-
export { AUTHENTICATION_EVENTS_NAMESPACE, ApiKeyAccess, AppExceptionsFilterBase, AppHashingService, AppInMemorySettings, AppSession, AppSessionMiddleware, AppSessionService, AuthGuard, Authenticated, AuthenticationEmailTemplates, AuthenticationError, AuthenticationEvents, AuthenticationExtensionSymbols, AuthenticationModule, AuthenticationService, AwsBucketModule, AwsDynamoDbModule, AwsEmailModule, AwsJobsModule, AwsS3BucketError, AwsS3BucketProvider, AwsS3MediaError, AwsS3MediaModule, AwsS3MediaProvider, AwsSecretsModule, AwsSecretsProvider, AwsSesEmailTemplate, BucketItemType, CacheService, ConnectorMode, CurrentUser, CustomDiscoveryModule, CustomDiscoveryService, DynamoDbCacheInstance, DynamoDbCollection, EmailService, EntityManagerConfigurationError, EntityManagerException, EntityManagerInitializer, EntityManagerModule, EntityManagerRegistry, EntityManagerService, EntityManagerSymbols, EntityManagerUnauthorizedException, EntityNotFoundException, EntityOperationType, EntityOperationUnauthorizedException, EntityParseResult, EntityParseValidationError, EntitySeeder, EntitySerializationFormat, EntitySerializer, EntitySnapshotService, EntityVersionOperation, EventsService, ExclusiveOperationResult, FilesManager, IEntityVersionsCursor, InMemoryBucketProvider, InMemoryEmailProvider, InMemoryFileProvider, InMemoryMediaProvider, InMemorySecretsProvider, InvalidCredentialsError, JobConcurrency, JobInstance, JobProviderState, JobRunType, JobSchedule, JobStatus, JobsModule, JobsService, LockNotFoundError, MediaLibraryService, MemberOf, MissingEntityIdError, ModulesContainerProvider, MultiTenancyModule, MultipleEntitiesFoundException, NestEntityActions, NestEntityAuthorizationMiddleware, NestEntityManager, NestEntitySerializer, NestEntitySnapshotService, NestPipelineTemplate, NestTypeOrmEntitySeeder, NestTypeOrmQueryBuilder, NestTypeOrmRepository, OperationLockService, OperationTokenMismatchError, PLATFORM_EVENT_NAMESPACE, Permissions, PipelineController, PipelineErrorType, PipelineInvocationError, PipelineStatus, PipelineStepErrorType, PipelinesBuilder, PipelinesRunner, PlatformEvents, Public, QueryBuilderBase, QueryBuilderOperation, ReplicationMode, Roles, SanityMediaError, SanityMediaModule, SanityMediaProvider, SecretsService, SendgridEmailModule, SendgridEmailTemplate, SortDirection, TestingAppSessionService, TrackingService, TypeOrmQueryBuilder, TypeOrmRepository, TypeormCacheInstance, TypeormOperationLockRepository, UserCreationError, UserRegistrationError, WpApiKeysService, WpAppInitializer, WpAwsSesEmailTemplate, WpBucketProvider, WpCacheInstance, WpEmailLogger, WpEmailProvider, WpEmailTemplate, WpEmailTemplateMiddleware, WpEntity, WpEntityActions, WpEntityAdapter, WpEntityAuthMiddleware, WpEntityConnector, WpEntityConnectorMapper, WpEntityConverter, WpEntityManager, WpEntityQueryBuilder, WpEntityRepository, WpEntitySeeder, WpEntitySerializer, WpEntitySnapshotService, WpEntityVersioningProvider, WpEventsTracker, WpFileProvider, WpFileReferenceRepository, WpGlobalAuthenticationMiddleware, WpMediaFolderRepository, WpMediaProvider, WpMediaReferenceRepository, WpPermissionsService, WpPipeline, WpRolesService, WpSendgridEmailTemplate, WpUserRolesService, WpUserService, awsBatchSettings, buildPermissionsGuard, buildProviderToken, buildRolesGuard, createContainer, createExpressFileResponse, fieldRequiredValidator, getEntityManagerProviderToken, getLocalizedText, newUuid, renderHandlebarsTemplate, sessionStorage, toEntitiesImportInput };
|
|
44621
|
+
export { AUTHENTICATION_EVENTS_NAMESPACE, ApiKeyAccess, AppExceptionsFilterBase, AppHashingService, AppInMemorySettings, AppSession, AppSessionMiddleware, AppSessionService, AuthGuard, Authenticated, AuthenticationEmailTemplates, AuthenticationError, AuthenticationEvents, AuthenticationExtensionSymbols, AuthenticationModule, AuthenticationService, AwsBucketModule, AwsDynamoDbModule, AwsEmailModule, AwsJobsModule, AwsS3BucketError, AwsS3BucketProvider, AwsS3MediaError, AwsS3MediaModule, AwsS3MediaProvider, AwsSecretsModule, AwsSecretsProvider, AwsSesEmailTemplate, BucketItemType, CacheService, ConnectorMode, CurrentUser, CustomDiscoveryModule, CustomDiscoveryService, DynamoDbCacheInstance, DynamoDbCollection, EmailService, EntityManagerConfigurationError, EntityManagerException, EntityManagerInitializer, EntityManagerModule, EntityManagerRegistry, EntityManagerService, EntityManagerSymbols, EntityManagerUnauthorizedException, EntityNotFoundException, EntityOperationType, EntityOperationUnauthorizedException, EntityParseResult, EntityParseValidationError, EntitySeeder, EntitySerializationFormat, EntitySerializer, EntitySnapshotService, EntityVersionOperation, EventsService, ExclusiveOperationResult, FilesManager, IEntityVersionsCursor, InMemoryBucketProvider, InMemoryEmailProvider, InMemoryFileProvider, InMemoryMediaProvider, InMemorySecretsProvider, InvalidCredentialsError, JobConcurrency, JobInstance, JobProviderState, JobRunType, JobSchedule, JobStatus, JobsModule, JobsService, LockNotFoundError, MediaLibraryService, MemberOf, MissingEntityIdError, ModulesContainerProvider, MultiTenancyModule, MultipleEntitiesFoundException, NestEntityActions, NestEntityAuthorizationMiddleware, NestEntityManager, NestEntitySerializer, NestEntitySnapshotService, NestPipelineTemplate, NestTypeOrmEntitySeeder, NestTypeOrmQueryBuilder, NestTypeOrmRepository, OperationLockService, OperationTokenMismatchError, PLATFORM_EVENT_NAMESPACE, Permissions, PipelineController, PipelineErrorType, PipelineInvocationError, PipelineStatus, PipelineStepErrorType, PipelinesBuilder, PipelinesRunner, PlatformEvents, Public, QueryBuilderBase, QueryBuilderOperation, ReplicationMode, Roles, SanityMediaError, SanityMediaModule, SanityMediaProvider, SecretsService, SendgridEmailModule, SendgridEmailTemplate, SortDirection, TasksModule, TestingAppSessionService, TrackingService, TypeOrmQueryBuilder, TypeOrmRepository, TypeormCacheInstance, TypeormOperationLockRepository, UserCreationError, UserRegistrationError, WpApiKeysService, WpAppInitializer, WpAwsSesEmailTemplate, WpBucketProvider, WpCacheInstance, WpEmailLogger, WpEmailProvider, WpEmailTemplate, WpEmailTemplateMiddleware, WpEntity, WpEntityActions, WpEntityAdapter, WpEntityAuthMiddleware, WpEntityConnector, WpEntityConnectorMapper, WpEntityConverter, WpEntityManager, WpEntityQueryBuilder, WpEntityRepository, WpEntitySeeder, WpEntitySerializer, WpEntitySnapshotService, WpEntityVersioningProvider, WpEventsTracker, WpFileProvider, WpFileReferenceRepository, WpGlobalAuthenticationMiddleware, WpMediaFolderRepository, WpMediaProvider, WpMediaReferenceRepository, WpPermissionsService, WpPipeline, WpRolesService, WpSendgridEmailTemplate, WpTask, WpUserRolesService, WpUserService, awsBatchSettings, buildPermissionsGuard, buildProviderToken, buildRolesGuard, createContainer, createExpressFileResponse, fieldRequiredValidator, getEntityManagerProviderToken, getLocalizedText, newUuid, renderHandlebarsTemplate, sessionStorage, toEntitiesImportInput };
|
|
44414
44622
|
//# sourceMappingURL=index.js.map
|