@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/cjs/index.js
CHANGED
|
@@ -231,8 +231,10 @@ class EntitySerializer {
|
|
|
231
231
|
return records.map((x, i) => this.convertSheetRecord(x, definition, i));
|
|
232
232
|
}
|
|
233
233
|
parseXlsx(data, definition) {
|
|
234
|
+
const dateColumns = definition.columns.filter((x) => x.sheetParser === "date");
|
|
234
235
|
const records = backendCore.excelParse(data, {
|
|
235
236
|
keysTransform: backendCore.ExcelKeyTransform.Lower,
|
|
237
|
+
dateColumns: dateColumns.map((x) => x.name),
|
|
236
238
|
});
|
|
237
239
|
return records.map((x, i) => this.convertSheetRecord(x, definition, i));
|
|
238
240
|
}
|
|
@@ -4260,6 +4262,19 @@ const WpEntitySnapshotService = (entityName, props = {}) => common.applyDecorato
|
|
|
4260
4262
|
...props,
|
|
4261
4263
|
}));
|
|
4262
4264
|
|
|
4265
|
+
const TASK_KEY = "wp_task";
|
|
4266
|
+
var TaskConcurrency;
|
|
4267
|
+
(function (TaskConcurrency) {
|
|
4268
|
+
TaskConcurrency["Single"] = "single";
|
|
4269
|
+
TaskConcurrency["Multiple"] = "multiple";
|
|
4270
|
+
})(TaskConcurrency || (TaskConcurrency = {}));
|
|
4271
|
+
function WpTask(name, settings) {
|
|
4272
|
+
return common.applyDecorators(common.Injectable(), common.SetMetadata(TASK_KEY, {
|
|
4273
|
+
name,
|
|
4274
|
+
...settings,
|
|
4275
|
+
}));
|
|
4276
|
+
}
|
|
4277
|
+
|
|
4263
4278
|
const WpEventsTracker = (props = {}) => common.applyDecorators(common.Injectable(), common.SetMetadata(EntityManagerSymbols.EventsTracker, {
|
|
4264
4279
|
...props,
|
|
4265
4280
|
}));
|
|
@@ -22235,26 +22250,6 @@ exports.MediaLibraryService = __decorate([
|
|
|
22235
22250
|
__metadata("design:paramtypes", [exports.EntityManagerRegistry])
|
|
22236
22251
|
], exports.MediaLibraryService);
|
|
22237
22252
|
|
|
22238
|
-
function toInteger(dirtyNumber) {
|
|
22239
|
-
if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
|
|
22240
|
-
return NaN;
|
|
22241
|
-
}
|
|
22242
|
-
|
|
22243
|
-
var number = Number(dirtyNumber);
|
|
22244
|
-
|
|
22245
|
-
if (isNaN(number)) {
|
|
22246
|
-
return number;
|
|
22247
|
-
}
|
|
22248
|
-
|
|
22249
|
-
return number < 0 ? Math.ceil(number) : Math.floor(number);
|
|
22250
|
-
}
|
|
22251
|
-
|
|
22252
|
-
function requiredArgs(required, args) {
|
|
22253
|
-
if (args.length < required) {
|
|
22254
|
-
throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present');
|
|
22255
|
-
}
|
|
22256
|
-
}
|
|
22257
|
-
|
|
22258
22253
|
/**
|
|
22259
22254
|
* @name toDate
|
|
22260
22255
|
* @category Common Helpers
|
|
@@ -22271,9 +22266,11 @@ function requiredArgs(required, args) {
|
|
|
22271
22266
|
*
|
|
22272
22267
|
* **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
|
|
22273
22268
|
*
|
|
22274
|
-
* @
|
|
22275
|
-
*
|
|
22276
|
-
* @
|
|
22269
|
+
* @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).
|
|
22270
|
+
*
|
|
22271
|
+
* @param argument - The value to convert
|
|
22272
|
+
*
|
|
22273
|
+
* @returns The parsed date in the local time zone
|
|
22277
22274
|
*
|
|
22278
22275
|
* @example
|
|
22279
22276
|
* // Clone the date:
|
|
@@ -22285,28 +22282,68 @@ function requiredArgs(required, args) {
|
|
|
22285
22282
|
* const result = toDate(1392098430000)
|
|
22286
22283
|
* //=> Tue Feb 11 2014 11:30:30
|
|
22287
22284
|
*/
|
|
22288
|
-
|
|
22289
22285
|
function toDate(argument) {
|
|
22290
|
-
|
|
22291
|
-
var argStr = Object.prototype.toString.call(argument); // Clone the date
|
|
22286
|
+
const argStr = Object.prototype.toString.call(argument);
|
|
22292
22287
|
|
|
22293
|
-
|
|
22288
|
+
// Clone the date
|
|
22289
|
+
if (
|
|
22290
|
+
argument instanceof Date ||
|
|
22291
|
+
(typeof argument === "object" && argStr === "[object Date]")
|
|
22292
|
+
) {
|
|
22294
22293
|
// Prevent the date to lose the milliseconds when passed to new Date() in IE10
|
|
22295
|
-
return new
|
|
22296
|
-
} else if (
|
|
22294
|
+
return new argument.constructor(+argument);
|
|
22295
|
+
} else if (
|
|
22296
|
+
typeof argument === "number" ||
|
|
22297
|
+
argStr === "[object Number]" ||
|
|
22298
|
+
typeof argument === "string" ||
|
|
22299
|
+
argStr === "[object String]"
|
|
22300
|
+
) {
|
|
22301
|
+
// TODO: Can we get rid of as?
|
|
22297
22302
|
return new Date(argument);
|
|
22298
22303
|
} else {
|
|
22299
|
-
|
|
22300
|
-
// eslint-disable-next-line no-console
|
|
22301
|
-
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
|
|
22302
|
-
|
|
22303
|
-
console.warn(new Error().stack);
|
|
22304
|
-
}
|
|
22305
|
-
|
|
22304
|
+
// TODO: Can we get rid of as?
|
|
22306
22305
|
return new Date(NaN);
|
|
22307
22306
|
}
|
|
22308
22307
|
}
|
|
22309
22308
|
|
|
22309
|
+
/**
|
|
22310
|
+
* @name constructFrom
|
|
22311
|
+
* @category Generic Helpers
|
|
22312
|
+
* @summary Constructs a date using the reference date and the value
|
|
22313
|
+
*
|
|
22314
|
+
* @description
|
|
22315
|
+
* The function constructs a new date using the constructor from the reference
|
|
22316
|
+
* date and the given value. It helps to build generic functions that accept
|
|
22317
|
+
* date extensions.
|
|
22318
|
+
*
|
|
22319
|
+
* It defaults to `Date` if the passed reference date is a number or a string.
|
|
22320
|
+
*
|
|
22321
|
+
* @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).
|
|
22322
|
+
*
|
|
22323
|
+
* @param date - The reference date to take constructor from
|
|
22324
|
+
* @param value - The value to create the date
|
|
22325
|
+
*
|
|
22326
|
+
* @returns Date initialized using the given date and value
|
|
22327
|
+
*
|
|
22328
|
+
* @example
|
|
22329
|
+
* import { constructFrom } from 'date-fns'
|
|
22330
|
+
*
|
|
22331
|
+
* // A function that clones a date preserving the original type
|
|
22332
|
+
* function cloneDate<DateType extends Date(date: DateType): DateType {
|
|
22333
|
+
* return constructFrom(
|
|
22334
|
+
* date, // Use contrustor from the given date
|
|
22335
|
+
* date.getTime() // Use the date value to create a new date
|
|
22336
|
+
* )
|
|
22337
|
+
* }
|
|
22338
|
+
*/
|
|
22339
|
+
function constructFrom(date, value) {
|
|
22340
|
+
if (date instanceof Date) {
|
|
22341
|
+
return new date.constructor(value);
|
|
22342
|
+
} else {
|
|
22343
|
+
return new Date(value);
|
|
22344
|
+
}
|
|
22345
|
+
}
|
|
22346
|
+
|
|
22310
22347
|
/**
|
|
22311
22348
|
* @name addDays
|
|
22312
22349
|
* @category Day Helpers
|
|
@@ -22315,37 +22352,60 @@ function toDate(argument) {
|
|
|
22315
22352
|
* @description
|
|
22316
22353
|
* Add the specified number of days to the given date.
|
|
22317
22354
|
*
|
|
22318
|
-
*
|
|
22355
|
+
* @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).
|
|
22319
22356
|
*
|
|
22320
|
-
*
|
|
22357
|
+
* @param date - The date to be changed
|
|
22358
|
+
* @param amount - The amount of days to be added.
|
|
22321
22359
|
*
|
|
22322
|
-
* @
|
|
22323
|
-
* @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`.
|
|
22324
|
-
* @returns {Date} the new date with the days added
|
|
22325
|
-
* @throws {TypeError} 2 arguments required
|
|
22360
|
+
* @returns The new date with the days added
|
|
22326
22361
|
*
|
|
22327
22362
|
* @example
|
|
22328
22363
|
* // Add 10 days to 1 September 2014:
|
|
22329
|
-
*
|
|
22364
|
+
* const result = addDays(new Date(2014, 8, 1), 10)
|
|
22330
22365
|
* //=> Thu Sep 11 2014 00:00:00
|
|
22331
22366
|
*/
|
|
22332
|
-
|
|
22333
|
-
|
|
22334
|
-
|
|
22335
|
-
var date = toDate(dirtyDate);
|
|
22336
|
-
var amount = toInteger(dirtyAmount);
|
|
22337
|
-
|
|
22338
|
-
if (isNaN(amount)) {
|
|
22339
|
-
return new Date(NaN);
|
|
22340
|
-
}
|
|
22341
|
-
|
|
22367
|
+
function addDays(date, amount) {
|
|
22368
|
+
const _date = toDate(date);
|
|
22369
|
+
if (isNaN(amount)) return constructFrom(date, NaN);
|
|
22342
22370
|
if (!amount) {
|
|
22343
22371
|
// If 0 days, no-op to avoid changing times in the hour before end of DST
|
|
22344
|
-
return
|
|
22372
|
+
return _date;
|
|
22345
22373
|
}
|
|
22374
|
+
_date.setDate(_date.getDate() + amount);
|
|
22375
|
+
return _date;
|
|
22376
|
+
}
|
|
22346
22377
|
|
|
22347
|
-
|
|
22348
|
-
|
|
22378
|
+
/**
|
|
22379
|
+
* @module constants
|
|
22380
|
+
* @summary Useful constants
|
|
22381
|
+
* @description
|
|
22382
|
+
* Collection of useful date constants.
|
|
22383
|
+
*
|
|
22384
|
+
* The constants could be imported from `date-fns/constants`:
|
|
22385
|
+
*
|
|
22386
|
+
* ```ts
|
|
22387
|
+
* import { maxTime, minTime } from "./constants/date-fns/constants";
|
|
22388
|
+
*
|
|
22389
|
+
* function isAllowedTime(time) {
|
|
22390
|
+
* return time <= maxTime && time >= minTime;
|
|
22391
|
+
* }
|
|
22392
|
+
* ```
|
|
22393
|
+
*/
|
|
22394
|
+
|
|
22395
|
+
/**
|
|
22396
|
+
* @constant
|
|
22397
|
+
* @name millisecondsInMinute
|
|
22398
|
+
* @summary Milliseconds in 1 minute
|
|
22399
|
+
*/
|
|
22400
|
+
const millisecondsInMinute = 60000;
|
|
22401
|
+
|
|
22402
|
+
function getRoundingMethod(method) {
|
|
22403
|
+
return (number) => {
|
|
22404
|
+
const round = method ? Math[method] : Math.trunc;
|
|
22405
|
+
const result = round(number);
|
|
22406
|
+
// Prevent negative zero
|
|
22407
|
+
return result === 0 ? 0 : result;
|
|
22408
|
+
};
|
|
22349
22409
|
}
|
|
22350
22410
|
|
|
22351
22411
|
/**
|
|
@@ -22356,33 +22416,30 @@ function addDays(dirtyDate, dirtyAmount) {
|
|
|
22356
22416
|
* @description
|
|
22357
22417
|
* Get the number of milliseconds between the given dates.
|
|
22358
22418
|
*
|
|
22359
|
-
*
|
|
22419
|
+
* @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).
|
|
22360
22420
|
*
|
|
22361
|
-
*
|
|
22421
|
+
* @param dateLeft - The later date
|
|
22422
|
+
* @param dateRight - The earlier date
|
|
22362
22423
|
*
|
|
22363
|
-
* @
|
|
22364
|
-
* @param {Date|Number} dateRight - the earlier date
|
|
22365
|
-
* @returns {Number} the number of milliseconds
|
|
22366
|
-
* @throws {TypeError} 2 arguments required
|
|
22424
|
+
* @returns The number of milliseconds
|
|
22367
22425
|
*
|
|
22368
22426
|
* @example
|
|
22369
22427
|
* // How many milliseconds are between
|
|
22370
22428
|
* // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?
|
|
22371
|
-
*
|
|
22429
|
+
* const result = differenceInMilliseconds(
|
|
22372
22430
|
* new Date(2014, 6, 2, 12, 30, 21, 700),
|
|
22373
22431
|
* new Date(2014, 6, 2, 12, 30, 20, 600)
|
|
22374
22432
|
* )
|
|
22375
22433
|
* //=> 1100
|
|
22376
22434
|
*/
|
|
22377
|
-
|
|
22378
|
-
|
|
22379
|
-
requiredArgs(2, arguments);
|
|
22380
|
-
var dateLeft = toDate(dirtyDateLeft);
|
|
22381
|
-
var dateRight = toDate(dirtyDateRight);
|
|
22382
|
-
return dateLeft.getTime() - dateRight.getTime();
|
|
22435
|
+
function differenceInMilliseconds(dateLeft, dateRight) {
|
|
22436
|
+
return +toDate(dateLeft) - +toDate(dateRight);
|
|
22383
22437
|
}
|
|
22384
22438
|
|
|
22385
|
-
|
|
22439
|
+
/**
|
|
22440
|
+
* The {@link differenceInMinutes} function options.
|
|
22441
|
+
*/
|
|
22442
|
+
|
|
22386
22443
|
/**
|
|
22387
22444
|
* @name differenceInMinutes
|
|
22388
22445
|
* @category Minute Helpers
|
|
@@ -22391,36 +22448,34 @@ var MILLISECONDS_IN_MINUTE = 60000;
|
|
|
22391
22448
|
* @description
|
|
22392
22449
|
* Get the signed number of full (rounded towards 0) minutes between the given dates.
|
|
22393
22450
|
*
|
|
22394
|
-
*
|
|
22451
|
+
* @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).
|
|
22395
22452
|
*
|
|
22396
|
-
*
|
|
22453
|
+
* @param dateLeft - The later date
|
|
22454
|
+
* @param dateRight - The earlier date
|
|
22455
|
+
* @param options - An object with options.
|
|
22397
22456
|
*
|
|
22398
|
-
* @
|
|
22399
|
-
* @param {Date|Number} dateRight - the earlier date
|
|
22400
|
-
* @returns {Number} the number of minutes
|
|
22401
|
-
* @throws {TypeError} 2 arguments required
|
|
22457
|
+
* @returns The number of minutes
|
|
22402
22458
|
*
|
|
22403
22459
|
* @example
|
|
22404
22460
|
* // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
|
|
22405
|
-
*
|
|
22461
|
+
* const result = differenceInMinutes(
|
|
22406
22462
|
* new Date(2014, 6, 2, 12, 20, 0),
|
|
22407
22463
|
* new Date(2014, 6, 2, 12, 7, 59)
|
|
22408
22464
|
* )
|
|
22409
22465
|
* //=> 12
|
|
22410
22466
|
*
|
|
22411
22467
|
* @example
|
|
22412
|
-
* // How many minutes are
|
|
22413
|
-
*
|
|
22468
|
+
* // How many minutes are between 10:01:59 and 10:00:00
|
|
22469
|
+
* const result = differenceInMinutes(
|
|
22414
22470
|
* new Date(2000, 0, 1, 10, 0, 0),
|
|
22415
22471
|
* new Date(2000, 0, 1, 10, 1, 59)
|
|
22416
22472
|
* )
|
|
22417
22473
|
* //=> -1
|
|
22418
22474
|
*/
|
|
22419
|
-
|
|
22420
|
-
|
|
22421
|
-
|
|
22422
|
-
|
|
22423
|
-
return diff > 0 ? Math.floor(diff) : Math.ceil(diff);
|
|
22475
|
+
function differenceInMinutes(dateLeft, dateRight, options) {
|
|
22476
|
+
const diff =
|
|
22477
|
+
differenceInMilliseconds(dateLeft, dateRight) / millisecondsInMinute;
|
|
22478
|
+
return getRoundingMethod(options?.roundingMethod)(diff);
|
|
22424
22479
|
}
|
|
22425
22480
|
|
|
22426
22481
|
/**
|
|
@@ -22431,25 +22486,20 @@ function differenceInMinutes(dirtyDateLeft, dirtyDateRight) {
|
|
|
22431
22486
|
* @description
|
|
22432
22487
|
* Subtract the specified number of days from the given date.
|
|
22433
22488
|
*
|
|
22434
|
-
*
|
|
22489
|
+
* @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).
|
|
22435
22490
|
*
|
|
22436
|
-
*
|
|
22491
|
+
* @param date - The date to be changed
|
|
22492
|
+
* @param amount - The amount of days to be subtracted.
|
|
22437
22493
|
*
|
|
22438
|
-
* @
|
|
22439
|
-
* @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`.
|
|
22440
|
-
* @returns {Date} the new date with the days subtracted
|
|
22441
|
-
* @throws {TypeError} 2 arguments required
|
|
22494
|
+
* @returns The new date with the days subtracted
|
|
22442
22495
|
*
|
|
22443
22496
|
* @example
|
|
22444
22497
|
* // Subtract 10 days from 1 September 2014:
|
|
22445
|
-
*
|
|
22498
|
+
* const result = subDays(new Date(2014, 8, 1), 10)
|
|
22446
22499
|
* //=> Fri Aug 22 2014 00:00:00
|
|
22447
22500
|
*/
|
|
22448
|
-
|
|
22449
|
-
|
|
22450
|
-
requiredArgs(2, arguments);
|
|
22451
|
-
var amount = toInteger(dirtyAmount);
|
|
22452
|
-
return addDays(dirtyDate, -amount);
|
|
22501
|
+
function subDays(date, amount) {
|
|
22502
|
+
return addDays(date, -amount);
|
|
22453
22503
|
}
|
|
22454
22504
|
|
|
22455
22505
|
const WpOperationLockService = (props = {}) => common.applyDecorators(common.Injectable(), common.SetMetadata(EntityManagerSymbols.OperationLockService, {
|
|
@@ -34744,6 +34794,164 @@ exports.JobsModule = JobsModule_1 = __decorate([
|
|
|
34744
34794
|
JobsProviderFactory])
|
|
34745
34795
|
], exports.JobsModule);
|
|
34746
34796
|
|
|
34797
|
+
var TaskRunType;
|
|
34798
|
+
(function (TaskRunType) {
|
|
34799
|
+
TaskRunType["Scheduled"] = "Scheduled";
|
|
34800
|
+
TaskRunType["OnDemand"] = "OnDemand";
|
|
34801
|
+
})(TaskRunType || (TaskRunType = {}));
|
|
34802
|
+
|
|
34803
|
+
const getCronCurrentSchedule = (cronExpression, ref) => {
|
|
34804
|
+
const interval = parser$1.parseExpression(cronExpression, {
|
|
34805
|
+
currentDate: ref,
|
|
34806
|
+
});
|
|
34807
|
+
return interval.prev().toDate();
|
|
34808
|
+
};
|
|
34809
|
+
|
|
34810
|
+
function floorDateToSecond(date) {
|
|
34811
|
+
const flooredDate = new Date(date);
|
|
34812
|
+
flooredDate.setMilliseconds(0);
|
|
34813
|
+
return flooredDate;
|
|
34814
|
+
}
|
|
34815
|
+
|
|
34816
|
+
var TaskShell_1;
|
|
34817
|
+
let TaskShell = TaskShell_1 = class TaskShell {
|
|
34818
|
+
constructor(registry, operations) {
|
|
34819
|
+
this.registry = registry;
|
|
34820
|
+
this.operations = operations;
|
|
34821
|
+
this.logger = backendCore.Log.getLogger(TaskShell_1.name);
|
|
34822
|
+
}
|
|
34823
|
+
async executeTask(instance, settings) {
|
|
34824
|
+
switch (settings.concurrency) {
|
|
34825
|
+
case TaskConcurrency.Single:
|
|
34826
|
+
return await this.executeTaskSequential(instance, settings);
|
|
34827
|
+
case TaskConcurrency.Multiple:
|
|
34828
|
+
return await this.executeTaskParallel(instance, settings);
|
|
34829
|
+
default:
|
|
34830
|
+
throw new Error(`Unknown task concurrency: ${settings.concurrency}`);
|
|
34831
|
+
}
|
|
34832
|
+
}
|
|
34833
|
+
async executeTaskParallel(instance, settings) {
|
|
34834
|
+
await this.invokeTask(instance, settings);
|
|
34835
|
+
}
|
|
34836
|
+
async executeTaskSequential(instance, settings) {
|
|
34837
|
+
const currentSchedule = getCronCurrentSchedule(settings.cronExpression, new Date());
|
|
34838
|
+
const lockKey = this.getTaskLockKey(settings, currentSchedule);
|
|
34839
|
+
const lock = await this.operations.acquireLock({
|
|
34840
|
+
lockUid: lockKey,
|
|
34841
|
+
});
|
|
34842
|
+
if (lock.available) {
|
|
34843
|
+
await this.invokeTask(instance, settings);
|
|
34844
|
+
}
|
|
34845
|
+
}
|
|
34846
|
+
getTaskLockKey(settings, cronSchedule) {
|
|
34847
|
+
return `task:${settings.name}:${floorDateToSecond(cronSchedule).toISOString()}`;
|
|
34848
|
+
}
|
|
34849
|
+
async invokeTask(instance, settings) {
|
|
34850
|
+
try {
|
|
34851
|
+
this.logger.info(`Task ${settings.name} -> starting`);
|
|
34852
|
+
await instance.execute({
|
|
34853
|
+
name: settings.name,
|
|
34854
|
+
startedAt: new Date(),
|
|
34855
|
+
runId: backendCore.newUuid(),
|
|
34856
|
+
runType: TaskRunType.Scheduled,
|
|
34857
|
+
});
|
|
34858
|
+
this.logger.info(`Task ${settings.name} -> completed`);
|
|
34859
|
+
}
|
|
34860
|
+
catch (error) {
|
|
34861
|
+
this.logger.exception(`Task ${settings.name} -> failed`, error);
|
|
34862
|
+
}
|
|
34863
|
+
}
|
|
34864
|
+
get operationsLockService() {
|
|
34865
|
+
return this.registry
|
|
34866
|
+
.getContainer()
|
|
34867
|
+
.getEntitiesServicesLocator()
|
|
34868
|
+
.resolveOperationLockService();
|
|
34869
|
+
}
|
|
34870
|
+
};
|
|
34871
|
+
TaskShell = TaskShell_1 = __decorate([
|
|
34872
|
+
common.Injectable(),
|
|
34873
|
+
__param(1, common.Inject(getEntityManagerProviderToken("OperationsLockRepository"))),
|
|
34874
|
+
__metadata("design:paramtypes", [exports.EntityManagerRegistry, Object])
|
|
34875
|
+
], TaskShell);
|
|
34876
|
+
|
|
34877
|
+
var TaskScheduler_1;
|
|
34878
|
+
let TaskScheduler = TaskScheduler_1 = class TaskScheduler {
|
|
34879
|
+
constructor(schedulerRegistry, jobShell) {
|
|
34880
|
+
this.schedulerRegistry = schedulerRegistry;
|
|
34881
|
+
this.jobShell = jobShell;
|
|
34882
|
+
this.logger = new common.Logger(TaskScheduler_1.name);
|
|
34883
|
+
this.jobs = [];
|
|
34884
|
+
}
|
|
34885
|
+
async registerTask(job, instance) {
|
|
34886
|
+
const cronJob = new dist.CronJob(job.cronExpression, async (context) => {
|
|
34887
|
+
await this.jobShell.executeTask(instance, job);
|
|
34888
|
+
});
|
|
34889
|
+
this.schedulerRegistry.addCronJob(job.name, cronJob);
|
|
34890
|
+
cronJob.start();
|
|
34891
|
+
this.jobs.push(cronJob);
|
|
34892
|
+
this.logger.log(`Jobs ${job.name} registered`);
|
|
34893
|
+
}
|
|
34894
|
+
stopAllTasks() {
|
|
34895
|
+
this.jobs.forEach((job) => {
|
|
34896
|
+
job.stop();
|
|
34897
|
+
});
|
|
34898
|
+
}
|
|
34899
|
+
};
|
|
34900
|
+
TaskScheduler = TaskScheduler_1 = __decorate([
|
|
34901
|
+
common.Injectable(),
|
|
34902
|
+
__metadata("design:paramtypes", [schedule.SchedulerRegistry,
|
|
34903
|
+
TaskShell])
|
|
34904
|
+
], TaskScheduler);
|
|
34905
|
+
|
|
34906
|
+
var TasksInitializer_1;
|
|
34907
|
+
let TasksInitializer = TasksInitializer_1 = class TasksInitializer {
|
|
34908
|
+
constructor(discover, scheduler) {
|
|
34909
|
+
this.discover = discover;
|
|
34910
|
+
this.scheduler = scheduler;
|
|
34911
|
+
this.logger = new common.Logger(TasksInitializer_1.name);
|
|
34912
|
+
}
|
|
34913
|
+
async initialize(app) {
|
|
34914
|
+
await this.registerCronJobs();
|
|
34915
|
+
this.logger.log("Tasks initialized 🎰");
|
|
34916
|
+
}
|
|
34917
|
+
async registerCronJobs() {
|
|
34918
|
+
const tasks = await this.discoverTasks();
|
|
34919
|
+
const duplicatedJobs = tasks.filter((job, index, self) => index !== self.findIndex((t) => t.meta.name === job.meta.name));
|
|
34920
|
+
if (duplicatedJobs.length) {
|
|
34921
|
+
throw new Error(`Duplicated jobs found: ${duplicatedJobs
|
|
34922
|
+
.map((j) => j.meta.name)
|
|
34923
|
+
.join(", ")}`);
|
|
34924
|
+
}
|
|
34925
|
+
for (const task of tasks) {
|
|
34926
|
+
await this.scheduler.registerTask(task.meta, task.discoveredClass.instance);
|
|
34927
|
+
}
|
|
34928
|
+
}
|
|
34929
|
+
async discoverTasks() {
|
|
34930
|
+
return await this.discover.providersWithMetaAtKey(TASK_KEY);
|
|
34931
|
+
}
|
|
34932
|
+
};
|
|
34933
|
+
TasksInitializer = TasksInitializer_1 = __decorate([
|
|
34934
|
+
WpAppInitializer(),
|
|
34935
|
+
__metadata("design:paramtypes", [exports.CustomDiscoveryService,
|
|
34936
|
+
TaskScheduler])
|
|
34937
|
+
], TasksInitializer);
|
|
34938
|
+
|
|
34939
|
+
exports.TasksModule = class TasksModule {
|
|
34940
|
+
constructor(scheduler) {
|
|
34941
|
+
this.scheduler = scheduler;
|
|
34942
|
+
}
|
|
34943
|
+
onModuleDestroy() {
|
|
34944
|
+
this.scheduler.stopAllTasks();
|
|
34945
|
+
}
|
|
34946
|
+
};
|
|
34947
|
+
exports.TasksModule = __decorate([
|
|
34948
|
+
common.Module({
|
|
34949
|
+
imports: [exports.EntityManagerModule],
|
|
34950
|
+
providers: [TasksInitializer, TaskScheduler, TaskShell],
|
|
34951
|
+
}),
|
|
34952
|
+
__metadata("design:paramtypes", [TaskScheduler])
|
|
34953
|
+
], exports.TasksModule);
|
|
34954
|
+
|
|
34747
34955
|
const createExpressFileResponse = (res, file) => {
|
|
34748
34956
|
res.set({
|
|
34749
34957
|
"Content-Type": file.contentType,
|
|
@@ -44519,6 +44727,7 @@ exports.WpPermissionsService = WpPermissionsService;
|
|
|
44519
44727
|
exports.WpPipeline = WpPipeline;
|
|
44520
44728
|
exports.WpRolesService = WpRolesService;
|
|
44521
44729
|
exports.WpSendgridEmailTemplate = WpSendgridEmailTemplate;
|
|
44730
|
+
exports.WpTask = WpTask;
|
|
44522
44731
|
exports.WpUserRolesService = WpUserRolesService;
|
|
44523
44732
|
exports.WpUserService = WpUserService;
|
|
44524
44733
|
exports.awsBatchSettings = awsBatchSettings;
|