@easyrpa/sheduler 1.0.2 → 1.0.3

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 +32 -41
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,22 +1,16 @@
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 {
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 bree_1.default({
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 promises_1.default.access(this.pathJobs);
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 promises_1.default.mkdir(this.pathJobs, { recursive: true });
54
+ await fsPromises.mkdir(this.pathJobs, { recursive: true });
61
55
  }
62
56
  //Очистка директории со скриптами задач
63
57
  async clearJobsDirectory() {
64
- await promises_1.default.rm(this.pathJobs, { recursive: true });
65
- await promises_1.default.mkdir(this.pathJobs, { recursive: true });
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 promises_1.default.mkdir(path_1.default.join(this.pathJobs, jobOptions._id), {
64
+ await fsPromises.mkdir(path.join(this.pathJobs, jobOptions._id), {
71
65
  recursive: true,
72
66
  });
73
67
  // чтение данных схемы
74
- const decryptedData = crypto_ts_1.AES.decrypt(jobOptions.flow.content, this._encriptKey);
75
- const dataFlow = JSON.parse(decryptedData.toString(crypto_ts_1.enc.Utf8));
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 script_creator_1.ScriptCreator(this._collections);
78
- const scriptPath = await scriptCreator.createScript(path_1.default.join(this.pathJobs, jobOptions._id), dataFlow.nodes, dataFlow.edges);
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 = path_1.default.join(this.pathJobs, jobOptions._id);
98
- await promises_1.default.rm(pathScript, { recursive: true });
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
- exports.Sheduler = Sheduler;
168
- class Job {
161
+ export class Job {
169
162
  constructor(jobOption, pathJobs, pythonPath, defaultScriptName) {
170
163
  this.name = jobOption._id;
171
- this.path = path_1.default.join(process.cwd(), "assets", "scriptFlow.js");
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: path_1.default.join(pathJobs, jobOption._id, this._defaultScriptName),
194
+ scriptPythonPath: path.join(pathJobs, jobOption._id, this._defaultScriptName),
202
195
  pythonPath: this._pythonPath,
203
196
  },
204
197
  };
205
198
  }
206
199
  }
207
- exports.Job = Job;
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 || (exports.JobStatus = 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 || (exports.IntervalsJob = IntervalsJob = {}));
214
+ })(IntervalsJob || (IntervalsJob = {}));
223
215
  //utils
224
- exports.months = [
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
- exports.weekDays = [
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 => exports.weekDays[wd - 1]).join(',')}`;
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 => exports.months[ym - 1]).join(',')} month`;
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.2",
3
+ "version": "1.0.3",
4
4
  "description": "Sheduler for easy rpa",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",