@easyrpa/sheduler 1.0.5 → 1.0.7

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.
Files changed (2) hide show
  1. package/dist/index.js +41 -32
  2. package/package.json +2 -3
package/dist/index.js CHANGED
@@ -1,16 +1,22 @@
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 {
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getInterval = exports.weekDays = exports.months = exports.IntervalsJob = exports.JobStatus = exports.Job = exports.Sheduler = void 0;
7
+ const bree_1 = __importDefault(require("bree"));
8
+ const ts_worker_1 = __importDefault(require("@breejs/ts-worker"));
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 {
9
15
  constructor(config, handleGetCollections) {
10
16
  this._logger = config.logger;
11
17
  this._encriptKey = config.encriptKey;
12
18
  this._pythonPath = config.pythonPath;
13
- this._sheduler = new Bree({
19
+ this._sheduler = new bree_1.default({
14
20
  root: false,
15
21
  jobs: [],
16
22
  logger: this._logger,
@@ -36,7 +42,7 @@ export class Sheduler {
36
42
  async prepareJobsDirectory() {
37
43
  //Проверка наличия директории с задачами
38
44
  try {
39
- await fsPromises.access(this.pathJobs);
45
+ await promises_1.default.access(this.pathJobs);
40
46
  this.clearJobsDirectory();
41
47
  }
42
48
  catch (err) {
@@ -45,25 +51,25 @@ export class Sheduler {
45
51
  }
46
52
  //Создание директории со скриптами задач
47
53
  async createJobsDirectory() {
48
- await fsPromises.mkdir(this.pathJobs, { recursive: true });
54
+ await promises_1.default.mkdir(this.pathJobs, { recursive: true });
49
55
  }
50
56
  //Очистка директории со скриптами задач
51
57
  async clearJobsDirectory() {
52
- await fsPromises.rm(this.pathJobs, { recursive: true });
53
- await fsPromises.mkdir(this.pathJobs, { recursive: true });
58
+ await promises_1.default.rm(this.pathJobs, { recursive: true });
59
+ await promises_1.default.mkdir(this.pathJobs, { recursive: true });
54
60
  }
55
61
  //Создание директории одного скрипта
56
62
  async createPhytonScript(jobOptions) {
57
63
  // создаем директорию phyton скрипта
58
- await fsPromises.mkdir(path.join(this.pathJobs, jobOptions._id), {
64
+ await promises_1.default.mkdir(path_1.default.join(this.pathJobs, jobOptions._id), {
59
65
  recursive: true,
60
66
  });
61
67
  // чтение данных схемы
62
- const decryptedData = AES.decrypt(jobOptions.flow.content, this._encriptKey);
63
- const dataFlow = JSON.parse(decryptedData.toString(enc.Utf8));
68
+ const decryptedData = crypto_ts_1.AES.decrypt(jobOptions.flow.content, this._encriptKey);
69
+ const dataFlow = JSON.parse(decryptedData.toString(crypto_ts_1.enc.Utf8));
64
70
  // создаем python скрипт для схемы
65
- const scriptCreator = new ScriptCreator(this.handleGetCollections);
66
- const scriptPath = await scriptCreator.createScript(path.join(this.pathJobs, jobOptions._id), dataFlow.nodes, dataFlow.edges);
71
+ const scriptCreator = new script_creator_1.ScriptCreator(this.handleGetCollections);
72
+ const scriptPath = await scriptCreator.createScript(path_1.default.join(this.pathJobs, jobOptions._id), dataFlow.nodes, dataFlow.edges);
67
73
  return scriptPath;
68
74
  }
69
75
  //Создание директорий скриптов
@@ -82,8 +88,8 @@ export class Sheduler {
82
88
  }
83
89
  //Удаление директории одного скрипта
84
90
  async deletePhytonScript(jobOptions) {
85
- const pathScript = path.join(this.pathJobs, jobOptions._id);
86
- await fsPromises.rm(pathScript, { recursive: true });
91
+ const pathScript = path_1.default.join(this.pathJobs, jobOptions._id);
92
+ await promises_1.default.rm(pathScript, { recursive: true });
87
93
  return pathScript;
88
94
  }
89
95
  //Запуск задачи
@@ -152,10 +158,11 @@ export class Sheduler {
152
158
  });
153
159
  }
154
160
  }
155
- export class Job {
161
+ exports.Sheduler = Sheduler;
162
+ class Job {
156
163
  constructor(jobOption, pathJobs, pythonPath, defaultScriptName) {
157
164
  this.name = jobOption._id;
158
- this.path = path.join(process.cwd(), "assets", "scriptFlow.js");
165
+ this.path = path_1.default.join(process.cwd(), "assets", "scriptFlow.js");
159
166
  this.interval = jobOption.interval || 0;
160
167
  this._pythonPath = pythonPath;
161
168
  this._defaultScriptName = defaultScriptName || 'script.py';
@@ -185,29 +192,30 @@ export class Job {
185
192
  }
186
193
  this.worker = {
187
194
  workerData: {
188
- scriptPythonPath: path.join(pathJobs, jobOption._id, this._defaultScriptName),
195
+ scriptPythonPath: path_1.default.join(pathJobs, jobOption._id, this._defaultScriptName),
189
196
  pythonPath: this._pythonPath,
190
197
  },
191
198
  };
192
199
  }
193
200
  }
194
- export var JobStatus;
201
+ exports.Job = Job;
202
+ var JobStatus;
195
203
  (function (JobStatus) {
196
204
  JobStatus["STOPPED"] = "stopped";
197
205
  JobStatus["RUNNING"] = "running";
198
206
  JobStatus["WORKING"] = "working";
199
207
  JobStatus["ERROR"] = "error";
200
- })(JobStatus || (JobStatus = {}));
201
- export var IntervalsJob;
208
+ })(JobStatus || (exports.JobStatus = JobStatus = {}));
209
+ var IntervalsJob;
202
210
  (function (IntervalsJob) {
203
211
  IntervalsJob["SECONDS"] = "seconds";
204
212
  IntervalsJob["MINUTES"] = "minutes";
205
213
  IntervalsJob["HOURS"] = "hours";
206
214
  IntervalsJob["DAYS"] = "days";
207
215
  IntervalsJob["MONTHS"] = "months";
208
- })(IntervalsJob || (IntervalsJob = {}));
216
+ })(IntervalsJob || (exports.IntervalsJob = IntervalsJob = {}));
209
217
  //utils
210
- export const months = [
218
+ exports.months = [
211
219
  'January',
212
220
  'February',
213
221
  'March',
@@ -221,7 +229,7 @@ export const months = [
221
229
  'November',
222
230
  'December',
223
231
  ];
224
- export const weekDays = [
232
+ exports.weekDays = [
225
233
  'Monday',
226
234
  'Tuesday',
227
235
  'Wednesday',
@@ -230,7 +238,7 @@ export const weekDays = [
230
238
  'Saturday',
231
239
  'Sunday',
232
240
  ];
233
- export const getInterval = (jobOption) => {
241
+ const getInterval = (jobOption) => {
234
242
  if ((jobOption.intervalMeasur && jobOption.intervalValue) || jobOption.weekDays || jobOption.yearMonths) {
235
243
  let builder = '';
236
244
  if (jobOption.intervalMeasur && jobOption.intervalValue) {
@@ -254,12 +262,13 @@ export const getInterval = (jobOption) => {
254
262
  }
255
263
  }
256
264
  if (jobOption.weekDays && jobOption.weekDays.length > 0) {
257
- builder = `${builder} on ${jobOption.weekDays.map(wd => weekDays[wd - 1]).join(',')}`;
265
+ builder = `${builder} on ${jobOption.weekDays.map(wd => exports.weekDays[wd - 1]).join(',')}`;
258
266
  }
259
267
  if (jobOption.yearMonths && jobOption.yearMonths.length > 0) {
260
- builder = `${builder} of ${jobOption.yearMonths.map(ym => months[ym - 1]).join(',')} month`;
268
+ builder = `${builder} of ${jobOption.yearMonths.map(ym => exports.months[ym - 1]).join(',')} month`;
261
269
  }
262
270
  return builder;
263
271
  }
264
272
  return;
265
273
  };
274
+ exports.getInterval = getInterval;
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "@easyrpa/sheduler",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Sheduler for easy rpa",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
- "type": "module",
8
7
  "scripts": {
9
8
  "test": "echo \"Error: no test specified\" && exit 1",
10
9
  "build": "rimraf dist && tsc"
@@ -26,7 +25,7 @@
26
25
  ],
27
26
  "dependencies": {
28
27
  "@breejs/ts-worker": "^2.0.0",
29
- "@easyrpa/script-creator": "^1.0.9",
28
+ "@easyrpa/script-creator": "^1.0.11",
30
29
  "bree": "^9.2.9",
31
30
  "crypto-ts": "^1.0.2"
32
31
  },