@easyrpa/sheduler 1.0.2 → 1.0.4
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/index.js +32 -41
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
bree_1.default.extend(ts_worker_1.default);
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
12
|
-
const crypto_ts_1 = require("crypto-ts");
|
|
13
|
-
const script_creator_1 = require("@easyrpa/script-creator");
|
|
14
|
-
class Sheduler {
|
|
1
|
+
import Bree from "bree";
|
|
2
|
+
import tsWorker from "@breejs/ts-worker";
|
|
3
|
+
Bree.extend(tsWorker);
|
|
4
|
+
import path from "path";
|
|
5
|
+
import fsPromises from "fs/promises";
|
|
6
|
+
import { AES, enc } from "crypto-ts";
|
|
7
|
+
import { ScriptCreator } from "@easyrpa/script-creator";
|
|
8
|
+
export class Sheduler {
|
|
15
9
|
constructor(config, collections) {
|
|
16
10
|
this._logger = config.logger;
|
|
17
11
|
this._encriptKey = config.encriptKey;
|
|
18
12
|
this._pythonPath = config.pythonPath;
|
|
19
|
-
this._sheduler = new
|
|
13
|
+
this._sheduler = new Bree({
|
|
20
14
|
root: false,
|
|
21
15
|
jobs: [],
|
|
22
16
|
logger: this._logger,
|
|
@@ -48,7 +42,7 @@ class Sheduler {
|
|
|
48
42
|
async prepareJobsDirectory() {
|
|
49
43
|
//Проверка наличия директории с задачами
|
|
50
44
|
try {
|
|
51
|
-
await
|
|
45
|
+
await fsPromises.access(this.pathJobs);
|
|
52
46
|
this.clearJobsDirectory();
|
|
53
47
|
}
|
|
54
48
|
catch (err) {
|
|
@@ -57,25 +51,25 @@ class Sheduler {
|
|
|
57
51
|
}
|
|
58
52
|
//Создание директории со скриптами задач
|
|
59
53
|
async createJobsDirectory() {
|
|
60
|
-
await
|
|
54
|
+
await fsPromises.mkdir(this.pathJobs, { recursive: true });
|
|
61
55
|
}
|
|
62
56
|
//Очистка директории со скриптами задач
|
|
63
57
|
async clearJobsDirectory() {
|
|
64
|
-
await
|
|
65
|
-
await
|
|
58
|
+
await fsPromises.rm(this.pathJobs, { recursive: true });
|
|
59
|
+
await fsPromises.mkdir(this.pathJobs, { recursive: true });
|
|
66
60
|
}
|
|
67
61
|
//Создание директории одного скрипта
|
|
68
62
|
async createPhytonScript(jobOptions) {
|
|
69
63
|
// создаем директорию phyton скрипта
|
|
70
|
-
await
|
|
64
|
+
await fsPromises.mkdir(path.join(this.pathJobs, jobOptions._id), {
|
|
71
65
|
recursive: true,
|
|
72
66
|
});
|
|
73
67
|
// чтение данных схемы
|
|
74
|
-
const decryptedData =
|
|
75
|
-
const dataFlow = JSON.parse(decryptedData.toString(
|
|
68
|
+
const decryptedData = AES.decrypt(jobOptions.flow.content, this._encriptKey);
|
|
69
|
+
const dataFlow = JSON.parse(decryptedData.toString(enc.Utf8));
|
|
76
70
|
// создаем python скрипт для схемы
|
|
77
|
-
const scriptCreator = new
|
|
78
|
-
const scriptPath = await scriptCreator.createScript(
|
|
71
|
+
const scriptCreator = new ScriptCreator(this._collections);
|
|
72
|
+
const scriptPath = await scriptCreator.createScript(path.join(this.pathJobs, jobOptions._id), dataFlow.nodes, dataFlow.edges);
|
|
79
73
|
return scriptPath;
|
|
80
74
|
}
|
|
81
75
|
//Создание директорий скриптов
|
|
@@ -94,8 +88,8 @@ class Sheduler {
|
|
|
94
88
|
}
|
|
95
89
|
//Удаление директории одного скрипта
|
|
96
90
|
async deletePhytonScript(jobOptions) {
|
|
97
|
-
const pathScript =
|
|
98
|
-
await
|
|
91
|
+
const pathScript = path.join(this.pathJobs, jobOptions._id);
|
|
92
|
+
await fsPromises.rm(pathScript, { recursive: true });
|
|
99
93
|
return pathScript;
|
|
100
94
|
}
|
|
101
95
|
//Запуск задачи
|
|
@@ -164,11 +158,10 @@ class Sheduler {
|
|
|
164
158
|
});
|
|
165
159
|
}
|
|
166
160
|
}
|
|
167
|
-
|
|
168
|
-
class Job {
|
|
161
|
+
export class Job {
|
|
169
162
|
constructor(jobOption, pathJobs, pythonPath, defaultScriptName) {
|
|
170
163
|
this.name = jobOption._id;
|
|
171
|
-
this.path =
|
|
164
|
+
this.path = path.join(process.cwd(), "assets", "scriptFlow.js");
|
|
172
165
|
this.interval = jobOption.interval || 0;
|
|
173
166
|
this._pythonPath = pythonPath;
|
|
174
167
|
this._defaultScriptName = defaultScriptName || 'script.py';
|
|
@@ -198,30 +191,29 @@ class Job {
|
|
|
198
191
|
}
|
|
199
192
|
this.worker = {
|
|
200
193
|
workerData: {
|
|
201
|
-
scriptPythonPath:
|
|
194
|
+
scriptPythonPath: path.join(pathJobs, jobOption._id, this._defaultScriptName),
|
|
202
195
|
pythonPath: this._pythonPath,
|
|
203
196
|
},
|
|
204
197
|
};
|
|
205
198
|
}
|
|
206
199
|
}
|
|
207
|
-
|
|
208
|
-
var JobStatus;
|
|
200
|
+
export var JobStatus;
|
|
209
201
|
(function (JobStatus) {
|
|
210
202
|
JobStatus["STOPPED"] = "stopped";
|
|
211
203
|
JobStatus["RUNNING"] = "running";
|
|
212
204
|
JobStatus["WORKING"] = "working";
|
|
213
205
|
JobStatus["ERROR"] = "error";
|
|
214
|
-
})(JobStatus || (
|
|
215
|
-
var IntervalsJob;
|
|
206
|
+
})(JobStatus || (JobStatus = {}));
|
|
207
|
+
export var IntervalsJob;
|
|
216
208
|
(function (IntervalsJob) {
|
|
217
209
|
IntervalsJob["SECONDS"] = "seconds";
|
|
218
210
|
IntervalsJob["MINUTES"] = "minutes";
|
|
219
211
|
IntervalsJob["HOURS"] = "hours";
|
|
220
212
|
IntervalsJob["DAYS"] = "days";
|
|
221
213
|
IntervalsJob["MONTHS"] = "months";
|
|
222
|
-
})(IntervalsJob || (
|
|
214
|
+
})(IntervalsJob || (IntervalsJob = {}));
|
|
223
215
|
//utils
|
|
224
|
-
|
|
216
|
+
export const months = [
|
|
225
217
|
'January',
|
|
226
218
|
'February',
|
|
227
219
|
'March',
|
|
@@ -235,7 +227,7 @@ exports.months = [
|
|
|
235
227
|
'November',
|
|
236
228
|
'December',
|
|
237
229
|
];
|
|
238
|
-
|
|
230
|
+
export const weekDays = [
|
|
239
231
|
'Monday',
|
|
240
232
|
'Tuesday',
|
|
241
233
|
'Wednesday',
|
|
@@ -244,7 +236,7 @@ exports.weekDays = [
|
|
|
244
236
|
'Saturday',
|
|
245
237
|
'Sunday',
|
|
246
238
|
];
|
|
247
|
-
const getInterval = (jobOption) => {
|
|
239
|
+
export const getInterval = (jobOption) => {
|
|
248
240
|
if ((jobOption.intervalMeasur && jobOption.intervalValue) || jobOption.weekDays || jobOption.yearMonths) {
|
|
249
241
|
let builder = '';
|
|
250
242
|
if (jobOption.intervalMeasur && jobOption.intervalValue) {
|
|
@@ -268,13 +260,12 @@ const getInterval = (jobOption) => {
|
|
|
268
260
|
}
|
|
269
261
|
}
|
|
270
262
|
if (jobOption.weekDays && jobOption.weekDays.length > 0) {
|
|
271
|
-
builder = `${builder} on ${jobOption.weekDays.map(wd =>
|
|
263
|
+
builder = `${builder} on ${jobOption.weekDays.map(wd => weekDays[wd - 1]).join(',')}`;
|
|
272
264
|
}
|
|
273
265
|
if (jobOption.yearMonths && jobOption.yearMonths.length > 0) {
|
|
274
|
-
builder = `${builder} of ${jobOption.yearMonths.map(ym =>
|
|
266
|
+
builder = `${builder} of ${jobOption.yearMonths.map(ym => months[ym - 1]).join(',')} month`;
|
|
275
267
|
}
|
|
276
268
|
return builder;
|
|
277
269
|
}
|
|
278
270
|
return;
|
|
279
271
|
};
|
|
280
|
-
exports.getInterval = getInterval;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easyrpa/sheduler",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Sheduler for easy rpa",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@breejs/ts-worker": "^2.0.0",
|
|
29
|
-
"@easyrpa/script-creator": "^1.0.
|
|
29
|
+
"@easyrpa/script-creator": "^1.0.2",
|
|
30
30
|
"bree": "^9.2.9",
|
|
31
31
|
"crypto-ts": "^1.0.2"
|
|
32
32
|
},
|