pangea-server 3.2.5 → 3.3.0
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/helpers/job.helpers.d.ts +10 -2
- package/dist/helpers/job.helpers.js +19 -13
- package/package.json +3 -1
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { Db } from '../database';
|
|
2
|
-
type
|
|
2
|
+
type TaskFn = (db: Db) => Promise<void>;
|
|
3
|
+
type Timezone = 'UTC' | 'America/New_York' | 'America/Los_Angeles' | 'America/Argentina/Buenos_Aires' | 'America/Sao_Paulo' | 'Europe/London' | 'Europe/Madrid' | 'Africa/Johannesburg' | 'Asia/Tokyo' | 'Australia/Sydney';
|
|
4
|
+
type ScheduleConfig = {
|
|
5
|
+
expression: string;
|
|
6
|
+
taskFn: TaskFn;
|
|
7
|
+
timezone?: Timezone;
|
|
8
|
+
runOnInit?: boolean;
|
|
9
|
+
};
|
|
3
10
|
export declare abstract class Job {
|
|
4
|
-
static
|
|
11
|
+
static Schedule(config: ScheduleConfig): void;
|
|
12
|
+
private static __Run;
|
|
5
13
|
}
|
|
6
14
|
export interface JobCtor {
|
|
7
15
|
Init(): void;
|
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.Job = void 0;
|
|
7
|
+
const node_cron_1 = __importDefault(require("node-cron"));
|
|
4
8
|
const database_1 = require("../database");
|
|
5
9
|
class Job {
|
|
6
|
-
static
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
static Schedule(config) {
|
|
11
|
+
const { expression, taskFn, timezone = 'UTC', runOnInit = false } = config;
|
|
12
|
+
node_cron_1.default.schedule(expression, () => this.__Run(taskFn), { timezone, runOnInit });
|
|
13
|
+
}
|
|
14
|
+
static async __Run(taskFn) {
|
|
15
|
+
const tx = await (0, database_1.getDbClient)().transaction();
|
|
16
|
+
const db = new database_1.Db(tx);
|
|
17
|
+
try {
|
|
18
|
+
await taskFn(db);
|
|
19
|
+
await tx.commit();
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
await tx.rollback();
|
|
23
|
+
throw err;
|
|
24
|
+
}
|
|
19
25
|
}
|
|
20
26
|
}
|
|
21
27
|
exports.Job = Job;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pangea-server",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.3.0",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
7
7
|
],
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"morgan": "1.10.0",
|
|
50
50
|
"multer": "1.4.5-lts.2",
|
|
51
51
|
"mysql2": "3.14.0",
|
|
52
|
+
"node-cron": "3.0.3",
|
|
52
53
|
"nodemailer": "6.10.0",
|
|
53
54
|
"pangea-helpers": "1.3.85",
|
|
54
55
|
"reflect-metadata": "0.2.2",
|
|
@@ -71,6 +72,7 @@
|
|
|
71
72
|
"@types/morgan": "1.9.9",
|
|
72
73
|
"@types/multer": "1.4.12",
|
|
73
74
|
"@types/node": "20.2.5",
|
|
75
|
+
"@types/node-cron": "3.0.11",
|
|
74
76
|
"@types/nodemailer": "6.4.17",
|
|
75
77
|
"tsc-alias": "1.8.15",
|
|
76
78
|
"typescript": "5.2.2",
|