@easyrpa/sheduler 1.0.4 → 1.0.6

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.d.ts CHANGED
@@ -3,7 +3,6 @@ import { type WorkerOptions } from "node:worker_threads";
3
3
  import { CollectionType } from "@easyrpa/script-creator";
4
4
  export interface ISheduler {
5
5
  pathJobs: string;
6
- collections: CollectionType[];
7
6
  runJobs(jobsOptions: JobOptionsType[]): Promise<string[] | undefined>;
8
7
  runJob(jobOptions: JobOptionsType): Promise<string | undefined>;
9
8
  stopJob(jobOptions: JobOptionsType): Promise<string | undefined>;
@@ -28,12 +27,10 @@ export declare class Sheduler implements ISheduler {
28
27
  _sheduler: Bree;
29
28
  _encriptKey: string;
30
29
  _pythonPath: string;
31
- _collections: CollectionType[];
32
30
  _onWorkerCreated?: (id: string) => void | Promise<void>;
33
31
  _onWorkerDeleted?: (id: string) => void | Promise<void>;
34
- constructor(config: ShedulerConfig, collections?: CollectionType[]);
35
- get collections(): CollectionType[];
36
- set collections(cols: CollectionType[]);
32
+ handleGetCollections: () => Promise<CollectionType[]>;
33
+ constructor(config: ShedulerConfig, handleGetCollections: () => Promise<CollectionType[]>);
37
34
  prepareJobsDirectory(): Promise<void>;
38
35
  createJobsDirectory(): Promise<void>;
39
36
  clearJobsDirectory(): Promise<void>;
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 {
9
- constructor(config, collections) {
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 {
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,
@@ -28,21 +34,15 @@ export class Sheduler {
28
34
  this.pathJobs = config.pathJobs;
29
35
  this._onWorkerCreated = config.onWorkerCreated;
30
36
  this._onWorkerDeleted = config.onWorkerDeleted;
31
- this._collections = collections || [];
37
+ this.handleGetCollections = handleGetCollections;
32
38
  this.prepareJobsDirectory();
33
39
  this.addWorkerListeners();
34
40
  }
35
- get collections() {
36
- return this._collections;
37
- }
38
- set collections(cols) {
39
- this._collections = cols;
40
- }
41
41
  //Подготовка директории со скриптами задач
42
42
  async prepareJobsDirectory() {
43
43
  //Проверка наличия директории с задачами
44
44
  try {
45
- await fsPromises.access(this.pathJobs);
45
+ await promises_1.default.access(this.pathJobs);
46
46
  this.clearJobsDirectory();
47
47
  }
48
48
  catch (err) {
@@ -51,25 +51,25 @@ export class Sheduler {
51
51
  }
52
52
  //Создание директории со скриптами задач
53
53
  async createJobsDirectory() {
54
- await fsPromises.mkdir(this.pathJobs, { recursive: true });
54
+ await promises_1.default.mkdir(this.pathJobs, { recursive: true });
55
55
  }
56
56
  //Очистка директории со скриптами задач
57
57
  async clearJobsDirectory() {
58
- await fsPromises.rm(this.pathJobs, { recursive: true });
59
- 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 });
60
60
  }
61
61
  //Создание директории одного скрипта
62
62
  async createPhytonScript(jobOptions) {
63
63
  // создаем директорию phyton скрипта
64
- await fsPromises.mkdir(path.join(this.pathJobs, jobOptions._id), {
64
+ await promises_1.default.mkdir(path_1.default.join(this.pathJobs, jobOptions._id), {
65
65
  recursive: true,
66
66
  });
67
67
  // чтение данных схемы
68
- const decryptedData = AES.decrypt(jobOptions.flow.content, this._encriptKey);
69
- 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));
70
70
  // создаем python скрипт для схемы
71
- const scriptCreator = new ScriptCreator(this._collections);
72
- 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);
73
73
  return scriptPath;
74
74
  }
75
75
  //Создание директорий скриптов
@@ -88,8 +88,8 @@ export class Sheduler {
88
88
  }
89
89
  //Удаление директории одного скрипта
90
90
  async deletePhytonScript(jobOptions) {
91
- const pathScript = path.join(this.pathJobs, jobOptions._id);
92
- 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 });
93
93
  return pathScript;
94
94
  }
95
95
  //Запуск задачи
@@ -158,10 +158,11 @@ export class Sheduler {
158
158
  });
159
159
  }
160
160
  }
161
- export class Job {
161
+ exports.Sheduler = Sheduler;
162
+ class Job {
162
163
  constructor(jobOption, pathJobs, pythonPath, defaultScriptName) {
163
164
  this.name = jobOption._id;
164
- this.path = path.join(process.cwd(), "assets", "scriptFlow.js");
165
+ this.path = path_1.default.join(process.cwd(), "assets", "scriptFlow.js");
165
166
  this.interval = jobOption.interval || 0;
166
167
  this._pythonPath = pythonPath;
167
168
  this._defaultScriptName = defaultScriptName || 'script.py';
@@ -191,29 +192,30 @@ export class Job {
191
192
  }
192
193
  this.worker = {
193
194
  workerData: {
194
- scriptPythonPath: path.join(pathJobs, jobOption._id, this._defaultScriptName),
195
+ scriptPythonPath: path_1.default.join(pathJobs, jobOption._id, this._defaultScriptName),
195
196
  pythonPath: this._pythonPath,
196
197
  },
197
198
  };
198
199
  }
199
200
  }
200
- export var JobStatus;
201
+ exports.Job = Job;
202
+ var JobStatus;
201
203
  (function (JobStatus) {
202
204
  JobStatus["STOPPED"] = "stopped";
203
205
  JobStatus["RUNNING"] = "running";
204
206
  JobStatus["WORKING"] = "working";
205
207
  JobStatus["ERROR"] = "error";
206
- })(JobStatus || (JobStatus = {}));
207
- export var IntervalsJob;
208
+ })(JobStatus || (exports.JobStatus = JobStatus = {}));
209
+ var IntervalsJob;
208
210
  (function (IntervalsJob) {
209
211
  IntervalsJob["SECONDS"] = "seconds";
210
212
  IntervalsJob["MINUTES"] = "minutes";
211
213
  IntervalsJob["HOURS"] = "hours";
212
214
  IntervalsJob["DAYS"] = "days";
213
215
  IntervalsJob["MONTHS"] = "months";
214
- })(IntervalsJob || (IntervalsJob = {}));
216
+ })(IntervalsJob || (exports.IntervalsJob = IntervalsJob = {}));
215
217
  //utils
216
- export const months = [
218
+ exports.months = [
217
219
  'January',
218
220
  'February',
219
221
  'March',
@@ -227,7 +229,7 @@ export const months = [
227
229
  'November',
228
230
  'December',
229
231
  ];
230
- export const weekDays = [
232
+ exports.weekDays = [
231
233
  'Monday',
232
234
  'Tuesday',
233
235
  'Wednesday',
@@ -236,7 +238,7 @@ export const weekDays = [
236
238
  'Saturday',
237
239
  'Sunday',
238
240
  ];
239
- export const getInterval = (jobOption) => {
241
+ const getInterval = (jobOption) => {
240
242
  if ((jobOption.intervalMeasur && jobOption.intervalValue) || jobOption.weekDays || jobOption.yearMonths) {
241
243
  let builder = '';
242
244
  if (jobOption.intervalMeasur && jobOption.intervalValue) {
@@ -260,12 +262,13 @@ export const getInterval = (jobOption) => {
260
262
  }
261
263
  }
262
264
  if (jobOption.weekDays && jobOption.weekDays.length > 0) {
263
- builder = `${builder} on ${jobOption.weekDays.map(wd => weekDays[wd - 1]).join(',')}`;
265
+ builder = `${builder} on ${jobOption.weekDays.map(wd => exports.weekDays[wd - 1]).join(',')}`;
264
266
  }
265
267
  if (jobOption.yearMonths && jobOption.yearMonths.length > 0) {
266
- 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`;
267
269
  }
268
270
  return builder;
269
271
  }
270
272
  return;
271
273
  };
274
+ exports.getInterval = getInterval;
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "@easyrpa/sheduler",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
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.2",
28
+ "@easyrpa/script-creator": "^1.0.10",
30
29
  "bree": "^9.2.9",
31
30
  "crypto-ts": "^1.0.2"
32
31
  },