@webtypen/webframez-core 0.3.52 → 0.3.54
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/Backup/BackupOutputDrivers.d.ts +1 -0
- package/dist/Backup/BackupOutputDrivers.js +9 -0
- package/dist/Commands/QueueWorkerCommand.d.ts +6 -1
- package/dist/Commands/QueueWorkerCommand.js +75 -48
- package/dist/Commands/SystemCommands.d.ts +8 -0
- package/dist/Commands/SystemCommands.js +24 -0
- package/dist/ConsoleApplication.d.ts +1 -0
- package/dist/ConsoleApplication.js +4 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BackupOutputDrivers = void 0;
|
|
4
4
|
const LocalBackupOutputDriver_1 = require("./OutputDrivers/LocalBackupOutputDriver");
|
|
5
|
+
const SystemCommands_1 = require("../Commands/SystemCommands");
|
|
5
6
|
class BackupOutputDriversFacade {
|
|
6
7
|
constructor() {
|
|
7
8
|
this.drivers = {};
|
|
@@ -9,8 +10,16 @@ class BackupOutputDriversFacade {
|
|
|
9
10
|
}
|
|
10
11
|
register(name, driver) {
|
|
11
12
|
this.drivers[name] = driver;
|
|
13
|
+
this.registerCommands(driver);
|
|
12
14
|
return this;
|
|
13
15
|
}
|
|
16
|
+
registerCommands(driver) {
|
|
17
|
+
const commands = (driver === null || driver === void 0 ? void 0 : driver.commands) || (driver === null || driver === void 0 ? void 0 : driver.consoleCommands);
|
|
18
|
+
if (!commands) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
SystemCommands_1.SystemCommands.register(commands);
|
|
22
|
+
}
|
|
14
23
|
get(name) {
|
|
15
24
|
const driverClass = this.drivers[name];
|
|
16
25
|
if (!driverClass) {
|
|
@@ -10,6 +10,7 @@ export declare class QueueWorkerCommand extends ConsoleCommand {
|
|
|
10
10
|
autorestart: boolean;
|
|
11
11
|
workerOperationId: string | null;
|
|
12
12
|
workerHadError: boolean;
|
|
13
|
+
lastAutomationCheckAt: any;
|
|
13
14
|
jobsExecuted: number;
|
|
14
15
|
jobsSucceeded: number;
|
|
15
16
|
jobsFailed: number;
|
|
@@ -30,7 +31,11 @@ export declare class QueueWorkerCommand extends ConsoleCommand {
|
|
|
30
31
|
}): void;
|
|
31
32
|
getWorkerAutomation(): any[];
|
|
32
33
|
getWorkerJobclasses(): any[] | null;
|
|
33
|
-
|
|
34
|
+
private getWorkerTimezone;
|
|
35
|
+
private getAutomationExecutionPayload;
|
|
36
|
+
private createAutomationEntry;
|
|
37
|
+
private pushIfDue;
|
|
38
|
+
checkWorkerAutomation(since?: any, until?: any): any;
|
|
34
39
|
runAutomation(): Promise<void>;
|
|
35
40
|
getNextJobNumber(connection: any): Promise<number>;
|
|
36
41
|
checkStop(): boolean;
|
|
@@ -38,6 +38,7 @@ class QueueWorkerCommand extends ConsoleCommand_1.ConsoleCommand {
|
|
|
38
38
|
this.autorestart = false;
|
|
39
39
|
this.workerOperationId = null;
|
|
40
40
|
this.workerHadError = false;
|
|
41
|
+
this.lastAutomationCheckAt = null;
|
|
41
42
|
// Statistics
|
|
42
43
|
this.jobsExecuted = 0;
|
|
43
44
|
this.jobsSucceeded = 0;
|
|
@@ -306,14 +307,38 @@ class QueueWorkerCommand extends ConsoleCommand_1.ConsoleCommand {
|
|
|
306
307
|
}
|
|
307
308
|
return jobclasses;
|
|
308
309
|
}
|
|
309
|
-
|
|
310
|
+
getWorkerTimezone() {
|
|
311
|
+
return this.workerConfig.timezone ? this.workerConfig.timezone : "Europe/Berlin";
|
|
312
|
+
}
|
|
313
|
+
getAutomationExecutionPayload(automation, options) {
|
|
314
|
+
return automation.payload || (options && options.payload)
|
|
315
|
+
? Object.assign(Object.assign({}, (automation.payload ? automation.payload : {})), (options && options.payload ? options.payload : {})) : null;
|
|
316
|
+
}
|
|
317
|
+
createAutomationEntry(automation, type, value, options, executionIdentifier, executionKey, dueAt) {
|
|
318
|
+
return Object.assign(Object.assign({}, automation), { _execution: {
|
|
319
|
+
key: `${automation.jobclass}_${executionKey}${executionIdentifier ? "_" + executionIdentifier : ""}_${dueAt.format("YYYY-MM-DD_HH:mm")}`,
|
|
320
|
+
type: type,
|
|
321
|
+
value: value,
|
|
322
|
+
identifier: executionIdentifier,
|
|
323
|
+
scheduled_at: dueAt.toDate(),
|
|
324
|
+
payload: this.getAutomationExecutionPayload(automation, options),
|
|
325
|
+
} });
|
|
326
|
+
}
|
|
327
|
+
pushIfDue(out, entryFactory, dueAt, since, until) {
|
|
328
|
+
if (dueAt.isAfter(since) && !dueAt.isAfter(until)) {
|
|
329
|
+
out.push(entryFactory(dueAt));
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
checkWorkerAutomation(since, until) {
|
|
310
333
|
const workerAutomation = this.getWorkerAutomation();
|
|
311
334
|
if (!workerAutomation || workerAutomation.length < 1) {
|
|
312
335
|
return null;
|
|
313
336
|
}
|
|
314
337
|
const out = [];
|
|
315
338
|
const days = DateFunctions_1.DateFunctions.getDays();
|
|
316
|
-
const
|
|
339
|
+
const timezone = this.getWorkerTimezone();
|
|
340
|
+
const now = until ? until.clone().tz(timezone) : (0, moment_timezone_1.default)().tz(timezone);
|
|
341
|
+
const checkedSince = since ? since.clone().tz(timezone) : now.clone().startOf("minute").subtract(1, "millisecond");
|
|
317
342
|
let automationIndex = -1;
|
|
318
343
|
for (let automation of workerAutomation) {
|
|
319
344
|
automationIndex++;
|
|
@@ -357,61 +382,58 @@ class QueueWorkerCommand extends ConsoleCommand_1.ConsoleCommand {
|
|
|
357
382
|
const useType = days.includes(type) ? "day_in_week" : type;
|
|
358
383
|
const executionKey = type + "-" + (value !== undefined && value !== null ? value : "0");
|
|
359
384
|
const executionIdentifier = options && options.identifier ? options.identifier : automation.identifier ? automation.identifier : null;
|
|
360
|
-
const
|
|
385
|
+
const entryFactory = (dueAt, executionValue = value) => this.createAutomationEntry(automation, type, executionValue, options, executionIdentifier, executionKey, dueAt);
|
|
361
386
|
switch (useType) {
|
|
362
|
-
case "every_hour":
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
} }));
|
|
387
|
+
case "every_hour": {
|
|
388
|
+
const minute = parseInt(value && !isNaN(parseInt(value)) ? value : "0");
|
|
389
|
+
let dueAt = checkedSince.clone().startOf("hour").minute(minute).second(0).millisecond(0);
|
|
390
|
+
if (!dueAt.isAfter(checkedSince)) {
|
|
391
|
+
dueAt.add(1, "hour");
|
|
392
|
+
}
|
|
393
|
+
while (!dueAt.isAfter(now)) {
|
|
394
|
+
this.pushIfDue(out, (entryDueAt) => entryFactory(entryDueAt, minute), dueAt, checkedSince, now);
|
|
395
|
+
dueAt = dueAt.clone().add(1, "hour");
|
|
372
396
|
}
|
|
373
397
|
break;
|
|
374
|
-
|
|
398
|
+
}
|
|
399
|
+
case "every_x_mins": {
|
|
375
400
|
const intervalMinutes = parseInt(value);
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
.
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
? Object.assign(Object.assign({}, (automation.payload ? automation.payload : {})), (options.payload ? options.payload : {})) : null,
|
|
387
|
-
} }));
|
|
401
|
+
let dueAt = checkedSince.clone().startOf("minute").second(0).millisecond(0);
|
|
402
|
+
if (!dueAt.isAfter(checkedSince)) {
|
|
403
|
+
dueAt.add(1, "minute");
|
|
404
|
+
}
|
|
405
|
+
while (!dueAt.isAfter(now)) {
|
|
406
|
+
const diffMins = dueAt.diff(dueAt.clone().startOf("day"), "minutes");
|
|
407
|
+
if (diffMins % intervalMinutes === 0) {
|
|
408
|
+
this.pushIfDue(out, entryFactory, dueAt, checkedSince, now);
|
|
409
|
+
}
|
|
410
|
+
dueAt = dueAt.clone().add(1, "minute");
|
|
388
411
|
}
|
|
389
412
|
break;
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
? Object.assign(Object.assign({}, (automation.payload ? automation.payload : {})), (options.payload ? options.payload : {})) : null,
|
|
399
|
-
} }));
|
|
413
|
+
}
|
|
414
|
+
case "daily": {
|
|
415
|
+
let day = checkedSince.clone().startOf("day");
|
|
416
|
+
const endDay = now.clone().startOf("day");
|
|
417
|
+
while (!day.isAfter(endDay)) {
|
|
418
|
+
const dueAt = moment_timezone_1.default.tz(`${day.format("YYYY-MM-DD")} ${value}`, "YYYY-MM-DD HH:mm", timezone);
|
|
419
|
+
this.pushIfDue(out, entryFactory, dueAt, checkedSince, now);
|
|
420
|
+
day = day.clone().add(1, "day");
|
|
400
421
|
}
|
|
401
422
|
break;
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
423
|
+
}
|
|
424
|
+
case "day_in_week": {
|
|
425
|
+
const isoWeekday = days.indexOf(type) + 1;
|
|
426
|
+
let day = checkedSince.clone().startOf("day");
|
|
427
|
+
const endDay = now.clone().startOf("day");
|
|
428
|
+
while (!day.isAfter(endDay)) {
|
|
429
|
+
if (day.isoWeekday() === isoWeekday) {
|
|
430
|
+
const dueAt = moment_timezone_1.default.tz(`${day.format("YYYY-MM-DD")} ${value}`, "YYYY-MM-DD HH:mm", timezone);
|
|
431
|
+
this.pushIfDue(out, entryFactory, dueAt, checkedSince, now);
|
|
432
|
+
}
|
|
433
|
+
day = day.clone().add(1, "day");
|
|
413
434
|
}
|
|
414
435
|
break;
|
|
436
|
+
}
|
|
415
437
|
}
|
|
416
438
|
}
|
|
417
439
|
}
|
|
@@ -430,7 +452,12 @@ class QueueWorkerCommand extends ConsoleCommand_1.ConsoleCommand {
|
|
|
430
452
|
automationChecking = false;
|
|
431
453
|
break;
|
|
432
454
|
}
|
|
433
|
-
const
|
|
455
|
+
const now = (0, moment_timezone_1.default)().tz(this.getWorkerTimezone());
|
|
456
|
+
const checkedSince = this.lastAutomationCheckAt
|
|
457
|
+
? this.lastAutomationCheckAt.clone()
|
|
458
|
+
: now.clone().startOf("minute").subtract(1, "millisecond");
|
|
459
|
+
this.lastAutomationCheckAt = now.clone();
|
|
460
|
+
const checkAutomation = this.checkWorkerAutomation(checkedSince, now);
|
|
434
461
|
if (!checkAutomation || checkAutomation.length < 1) {
|
|
435
462
|
yield this.wait(5000);
|
|
436
463
|
continue;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SystemCommands = void 0;
|
|
4
|
+
class SystemCommandsFacade {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.commands = [];
|
|
7
|
+
this.registered = {};
|
|
8
|
+
}
|
|
9
|
+
register(data) {
|
|
10
|
+
const commands = Array.isArray(data) ? data : [data];
|
|
11
|
+
for (const command of commands) {
|
|
12
|
+
if (!command || !command.signature || this.registered[command.signature]) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
this.registered[command.signature] = true;
|
|
16
|
+
this.commands.push(command);
|
|
17
|
+
}
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
getCommands() {
|
|
21
|
+
return this.commands;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.SystemCommands = new SystemCommandsFacade();
|
|
@@ -29,6 +29,7 @@ const BackupRunCommand_1 = require("./Commands/BackupRunCommand");
|
|
|
29
29
|
const BackupQueueCommand_1 = require("./Commands/BackupQueueCommand");
|
|
30
30
|
const BackupCleanupCommand_1 = require("./Commands/BackupCleanupCommand");
|
|
31
31
|
const BackupRunJob_1 = require("./Backup/Jobs/BackupRunJob");
|
|
32
|
+
const SystemCommands_1 = require("./Commands/SystemCommands");
|
|
32
33
|
const ModulesLoader_1 = require("./Modules/ModulesLoader");
|
|
33
34
|
class ConsoleApplication {
|
|
34
35
|
constructor() {
|
|
@@ -46,6 +47,7 @@ class ConsoleApplication {
|
|
|
46
47
|
QueueWorkerAutorestartCommand_1.QueueWorkerAutorestartCommand,
|
|
47
48
|
BuildFinishCommand_1.BuildFinishCommand,
|
|
48
49
|
];
|
|
50
|
+
SystemCommands_1.SystemCommands.register(this.systemCommands);
|
|
49
51
|
}
|
|
50
52
|
/**
|
|
51
53
|
* Init the routes and start the http-server
|
|
@@ -120,7 +122,7 @@ class ConsoleApplication {
|
|
|
120
122
|
getCommand(signature, options) {
|
|
121
123
|
if (!signature || signature.trim() === "")
|
|
122
124
|
return null;
|
|
123
|
-
for (let command of
|
|
125
|
+
for (let command of SystemCommands_1.SystemCommands.getCommands()) {
|
|
124
126
|
if (command.signature === signature) {
|
|
125
127
|
return command;
|
|
126
128
|
}
|
|
@@ -174,7 +176,7 @@ class ConsoleApplication {
|
|
|
174
176
|
let maxSignatureLength = 15;
|
|
175
177
|
const groups = {};
|
|
176
178
|
// Load system commands
|
|
177
|
-
for (let command of
|
|
179
|
+
for (let command of SystemCommands_1.SystemCommands.getCommands()) {
|
|
178
180
|
if (!command || !command.signature || command.hidden)
|
|
179
181
|
continue;
|
|
180
182
|
let groupKey = " ";
|
package/dist/index.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export * from "./Backup/Jobs/BackupRunJob";
|
|
|
37
37
|
export * from "./Backup/OutputDrivers/BaseBackupOutputDriver";
|
|
38
38
|
export * from "./Backup/OutputDrivers/LocalBackupOutputDriver";
|
|
39
39
|
export * from "./Commands/ConsoleOutputHelper";
|
|
40
|
+
export * from "./Commands/SystemCommands";
|
|
40
41
|
export * from "./Modules/ModuleProvider";
|
|
41
42
|
export * from "./ErrorHandling/ErrorHandler";
|
|
42
43
|
export * from "./Hooks/WebframezHooks";
|
package/dist/index.js
CHANGED
|
@@ -53,6 +53,7 @@ __exportStar(require("./Backup/Jobs/BackupRunJob"), exports);
|
|
|
53
53
|
__exportStar(require("./Backup/OutputDrivers/BaseBackupOutputDriver"), exports);
|
|
54
54
|
__exportStar(require("./Backup/OutputDrivers/LocalBackupOutputDriver"), exports);
|
|
55
55
|
__exportStar(require("./Commands/ConsoleOutputHelper"), exports);
|
|
56
|
+
__exportStar(require("./Commands/SystemCommands"), exports);
|
|
56
57
|
__exportStar(require("./Modules/ModuleProvider"), exports);
|
|
57
58
|
__exportStar(require("./ErrorHandling/ErrorHandler"), exports);
|
|
58
59
|
__exportStar(require("./Hooks/WebframezHooks"), exports);
|
package/package.json
CHANGED