@stamhoofd/crons 2.117.0 → 2.118.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/src/crons.d.ts.map +1 -1
- package/dist/src/crons.js +37 -1
- package/dist/src/crons.js.map +1 -1
- package/package.json +2 -2
- package/src/crons.ts +40 -1
package/dist/src/crons.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crons.d.ts","sourceRoot":"","sources":["../../src/crons.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"crons.d.ts","sourceRoot":"","sources":["../../src/crons.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,iBAAiB,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,OAAO,EAAE,OAAO,CAAC;CACpB,CAAC;AAIF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,QAMrE;AAiHD,wBAAgB,UAAU,SASzB;AAED,wBAAgB,SAAS,SAOxB;AAED,wBAAsB,YAAY,kBAWjC"}
|
package/dist/src/crons.js
CHANGED
|
@@ -6,6 +6,7 @@ exports.stopCrons = stopCrons;
|
|
|
6
6
|
exports.waitForCrons = waitForCrons;
|
|
7
7
|
const simple_logging_1 = require("@simonbackx/simple-logging");
|
|
8
8
|
const utility_1 = require("@stamhoofd/utility");
|
|
9
|
+
const simple_database_1 = require("@simonbackx/simple-database");
|
|
9
10
|
const registeredCronJobs = [];
|
|
10
11
|
function registerCron(name, method) {
|
|
11
12
|
registeredCronJobs.push({
|
|
@@ -34,6 +35,35 @@ async function run(name, handler) {
|
|
|
34
35
|
console.error(new simple_logging_1.StyledText(e).addClass('error'));
|
|
35
36
|
}
|
|
36
37
|
}
|
|
38
|
+
async function checkReadOnly() {
|
|
39
|
+
// Check if database is in read only mode. If so, skip running cronjobs.
|
|
40
|
+
const [results] = await simple_database_1.Database.select("SHOW VARIABLES LIKE 'read_only'");
|
|
41
|
+
if (results.length !== 1) {
|
|
42
|
+
console.error('UNEXPECTED RESULT FOR checking read only mode on the server.');
|
|
43
|
+
console.error('Received', results);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const result = results[0]['session_variables'];
|
|
47
|
+
if (!result) {
|
|
48
|
+
console.error('UNEXPECTED RESULT FOR checking read only mode on the server.');
|
|
49
|
+
console.error('Received', results);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const value = result['Value'];
|
|
53
|
+
if (value !== 'ON' && value !== 'OFF') {
|
|
54
|
+
console.error('UNEXPECTED RESULT FOR checking read only mode on the server.');
|
|
55
|
+
console.error('Received', results);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
if (value === 'ON') {
|
|
59
|
+
console.error(new simple_logging_1.StyledText(`[CRONS] `).addClass('crons', 'tag'), new simple_logging_1.StyledText('MySQL is in read-only mode: crons are disabled.').addClass('error'));
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
37
67
|
let doStopCrons = false;
|
|
38
68
|
function stopCronScheduling() {
|
|
39
69
|
doStopCrons = true;
|
|
@@ -52,7 +82,10 @@ function areCronsRunning() {
|
|
|
52
82
|
}
|
|
53
83
|
async function crons() {
|
|
54
84
|
if (STAMHOOFD.CRONS_DISABLED) {
|
|
55
|
-
console.
|
|
85
|
+
console.error(new simple_logging_1.StyledText(`[CRONS] `).addClass('crons', 'tag'), new simple_logging_1.StyledText('Crons are disabled. Make sure to enable them in the environment variables.').addClass('error'));
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (await checkReadOnly()) {
|
|
56
89
|
return;
|
|
57
90
|
}
|
|
58
91
|
schedulingJobs = true;
|
|
@@ -74,6 +107,9 @@ async function crons() {
|
|
|
74
107
|
// Prevent starting too many jobs at once
|
|
75
108
|
if (STAMHOOFD.environment !== 'development') {
|
|
76
109
|
await (0, utility_1.sleep)(10 * 1000);
|
|
110
|
+
if (await checkReadOnly()) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
77
113
|
}
|
|
78
114
|
}
|
|
79
115
|
schedulingJobs = false;
|
package/dist/src/crons.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crons.js","sourceRoot":"","sources":["../../src/crons.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"crons.js","sourceRoot":"","sources":["../../src/crons.ts"],"names":[],"mappings":";;AAYA,oCAMC;AAiHD,gCASC;AAED,8BAOC;AAED,oCAWC;AAlKD,+DAAgE;AAChE,gDAA2C;AAC3C,iEAAuD;AAQvD,MAAM,kBAAkB,GAAwB,EAAE,CAAC;AAEnD,SAAgB,YAAY,CAAC,IAAY,EAAE,MAA2B;IAClE,kBAAkB,CAAC,IAAI,CAAC;QACpB,IAAI;QACJ,MAAM;QACN,OAAO,EAAE,KAAK;KACjB,CAAC,CAAC;AACP,CAAC;AAED,KAAK,UAAU,GAAG,CAAC,IAAY,EAAE,OAA4B;IACzD,IAAI,CAAC;QACD,MAAM,uBAAM,CAAC,UAAU,CAAC;YACpB,QAAQ,EAAE;gBACN,IAAI,2BAAU,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;aACxD;YACD,IAAI,EAAE,CAAC,OAAO,CAAC;SAClB,EAAE,KAAK,IAAI,EAAE;YACV,IAAI,CAAC;gBACD,MAAM,OAAO,EAAE,CAAC;YACpB,CAAC;YACD,OAAO,CAAC,EAAE,CAAC;gBACP,OAAO,CAAC,KAAK,CAAC,IAAI,2BAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;YACvD,CAAC;QACL,CAAC,CAAC,CAAC;IACP,C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AE,EAAE,CAAC;YACvB,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;YAC7D,MAAM,IAAA,eAAK,EAAC,IAAI,CAAC,CAAC;QACtB,CAAC;IACL,CAAC;IACD,OAAO,GAAG,EAAE,CAAC;QACT,OAAO,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACrD,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stamhoofd/crons",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.118.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"license": "UNLICENCED",
|
|
@@ -15,5 +15,5 @@
|
|
|
15
15
|
"publishConfig": {
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
|
-
"gitHead": "
|
|
18
|
+
"gitHead": "57fe442b1afa0bb2645295bed467c303b39a2573"
|
|
19
19
|
}
|
package/src/crons.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { logger, StyledText } from '@simonbackx/simple-logging';
|
|
2
2
|
import { sleep } from '@stamhoofd/utility';
|
|
3
|
+
import { Database } from '@simonbackx/simple-database';
|
|
3
4
|
|
|
4
5
|
export type CronJobDefinition = {
|
|
5
6
|
name: string;
|
|
@@ -38,6 +39,36 @@ async function run(name: string, handler: () => Promise<void>) {
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
async function checkReadOnly() {
|
|
43
|
+
// Check if database is in read only mode. If so, skip running cronjobs.
|
|
44
|
+
const [results] = await Database.select("SHOW VARIABLES LIKE 'read_only'");
|
|
45
|
+
if (results.length !== 1) {
|
|
46
|
+
console.error('UNEXPECTED RESULT FOR checking read only mode on the server.');
|
|
47
|
+
console.error('Received', results);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const result = results[0]['session_variables'];
|
|
51
|
+
if (!result) {
|
|
52
|
+
console.error('UNEXPECTED RESULT FOR checking read only mode on the server.');
|
|
53
|
+
console.error('Received', results);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const value = result['Value'];
|
|
57
|
+
if (value !== 'ON' && value !== 'OFF') {
|
|
58
|
+
console.error('UNEXPECTED RESULT FOR checking read only mode on the server.');
|
|
59
|
+
console.error('Received', results);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
if (value === 'ON') {
|
|
63
|
+
console.error(new StyledText(`[CRONS] `).addClass('crons', 'tag'), new StyledText('MySQL is in read-only mode: crons are disabled.').addClass('error'));
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
|
|
41
72
|
let doStopCrons = false;
|
|
42
73
|
function stopCronScheduling() {
|
|
43
74
|
doStopCrons = true;
|
|
@@ -59,7 +90,11 @@ function areCronsRunning(): boolean {
|
|
|
59
90
|
|
|
60
91
|
async function crons() {
|
|
61
92
|
if (STAMHOOFD.CRONS_DISABLED) {
|
|
62
|
-
console.
|
|
93
|
+
console.error(new StyledText(`[CRONS] `).addClass('crons', 'tag'), new StyledText('Crons are disabled. Make sure to enable them in the environment variables.').addClass('error'));
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (await checkReadOnly()) {
|
|
63
98
|
return;
|
|
64
99
|
}
|
|
65
100
|
|
|
@@ -83,6 +118,10 @@ async function crons() {
|
|
|
83
118
|
// Prevent starting too many jobs at once
|
|
84
119
|
if (STAMHOOFD.environment !== 'development') {
|
|
85
120
|
await sleep(10 * 1000);
|
|
121
|
+
|
|
122
|
+
if (await checkReadOnly()) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
86
125
|
}
|
|
87
126
|
}
|
|
88
127
|
schedulingJobs = false;
|