@easyrpa/sheduler 1.0.1 → 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.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import Bree from "bree";
2
- import { CollectionType } from "@easyrpa/script-creator/dist/types";
3
- import { ShedulerMessageType, ShedulerLogger, JobOptionsType } from "./types";
2
+ import { type WorkerOptions } from "node:worker_threads";
3
+ import { CollectionType } from "@easyrpa/script-creator";
4
4
  export interface ISheduler {
5
5
  pathJobs: string;
6
6
  collections: CollectionType[];
@@ -46,6 +46,82 @@ export declare class Sheduler implements ISheduler {
46
46
  postMessageCancelWorker(jobOptions: JobOptionsType): void;
47
47
  private addWorkerListeners;
48
48
  }
49
+ export interface IJob {
50
+ name: string;
51
+ path: string;
52
+ interval: number | string;
53
+ date?: Date;
54
+ cron?: string;
55
+ worker?: Partial<WorkerOptions>;
56
+ externalData: JobType;
57
+ }
58
+ export declare class Job implements IJob {
59
+ name: string;
60
+ path: string;
61
+ interval: number | string;
62
+ date?: Date;
63
+ cron?: string;
64
+ worker?: Partial<WorkerOptions>;
65
+ _pythonPath: string;
66
+ _defaultScriptName: string;
67
+ constructor(jobOption: JobOptionsType, pathJobs: string, pythonPath: string, defaultScriptName?: string);
68
+ get externalData(): JobType;
69
+ private init;
70
+ }
71
+ export type JobOptionsType = {
72
+ _id: string;
73
+ name: string;
74
+ status: JobStatus;
75
+ logs: JobLogType[];
76
+ flow: JobFlowType;
77
+ startDateTime: string;
78
+ interval?: string;
79
+ intervalMeasur?: IntervalsJob;
80
+ intervalValue?: number;
81
+ weekDays?: number[];
82
+ yearMonths?: number[];
83
+ endDateTime?: string;
84
+ };
85
+ export type JobType = {
86
+ name: string;
87
+ path: string;
88
+ interval: number | string;
89
+ date?: Date;
90
+ cron?: string;
91
+ worker?: Partial<WorkerOptions>;
92
+ };
93
+ export declare enum JobStatus {
94
+ STOPPED = "stopped",
95
+ RUNNING = "running",
96
+ WORKING = "working",
97
+ ERROR = "error"
98
+ }
99
+ export type JobLogType = {
100
+ category: 'run' | 'stop' | 'message' | 'workerCreated' | 'workerDeleted';
101
+ date: string;
102
+ message?: string;
103
+ };
104
+ export type JobFlowType = {
105
+ name: string;
106
+ content: string;
107
+ };
108
+ export declare enum IntervalsJob {
109
+ SECONDS = "seconds",
110
+ MINUTES = "minutes",
111
+ HOURS = "hours",
112
+ DAYS = "days",
113
+ MONTHS = "months"
114
+ }
115
+ export type ShedulerLogger = {
116
+ info(...args: string[]): void;
117
+ log(...args: string[]): void;
118
+ error(...args: string[]): void;
119
+ warn(...args: string[]): void;
120
+ };
121
+ export type ShedulerMessageType = {
122
+ name: string;
123
+ message: unknown;
124
+ };
49
125
  export declare const months: string[];
50
126
  export declare const weekDays: string[];
51
127
  export declare const getInterval: (jobOption: Partial<JobOptionsType>) => string | undefined;
package/dist/index.js CHANGED
@@ -1,24 +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.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
- const types_1 = require("./types");
15
- const Job_1 = require("./Job");
16
- 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 {
17
9
  constructor(config, collections) {
18
10
  this._logger = config.logger;
19
11
  this._encriptKey = config.encriptKey;
20
12
  this._pythonPath = config.pythonPath;
21
- this._sheduler = new bree_1.default({
13
+ this._sheduler = new Bree({
22
14
  root: false,
23
15
  jobs: [],
24
16
  logger: this._logger,
@@ -50,7 +42,7 @@ class Sheduler {
50
42
  async prepareJobsDirectory() {
51
43
  //Проверка наличия директории с задачами
52
44
  try {
53
- await promises_1.default.access(this.pathJobs);
45
+ await fsPromises.access(this.pathJobs);
54
46
  this.clearJobsDirectory();
55
47
  }
56
48
  catch (err) {
@@ -59,25 +51,25 @@ class Sheduler {
59
51
  }
60
52
  //Создание директории со скриптами задач
61
53
  async createJobsDirectory() {
62
- await promises_1.default.mkdir(this.pathJobs, { recursive: true });
54
+ await fsPromises.mkdir(this.pathJobs, { recursive: true });
63
55
  }
64
56
  //Очистка директории со скриптами задач
65
57
  async clearJobsDirectory() {
66
- await promises_1.default.rm(this.pathJobs, { recursive: true });
67
- 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 });
68
60
  }
69
61
  //Создание директории одного скрипта
70
62
  async createPhytonScript(jobOptions) {
71
63
  // создаем директорию phyton скрипта
72
- await promises_1.default.mkdir(path_1.default.join(this.pathJobs, jobOptions._id), {
64
+ await fsPromises.mkdir(path.join(this.pathJobs, jobOptions._id), {
73
65
  recursive: true,
74
66
  });
75
67
  // чтение данных схемы
76
- const decryptedData = crypto_ts_1.AES.decrypt(jobOptions.flow.content, this._encriptKey);
77
- 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));
78
70
  // создаем python скрипт для схемы
79
- const scriptCreator = new script_creator_1.ScriptCreator(this._collections);
80
- 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);
81
73
  return scriptPath;
82
74
  }
83
75
  //Создание директорий скриптов
@@ -96,8 +88,8 @@ class Sheduler {
96
88
  }
97
89
  //Удаление директории одного скрипта
98
90
  async deletePhytonScript(jobOptions) {
99
- const pathScript = path_1.default.join(this.pathJobs, jobOptions._id);
100
- await promises_1.default.rm(pathScript, { recursive: true });
91
+ const pathScript = path.join(this.pathJobs, jobOptions._id);
92
+ await fsPromises.rm(pathScript, { recursive: true });
101
93
  return pathScript;
102
94
  }
103
95
  //Запуск задачи
@@ -109,7 +101,7 @@ class Sheduler {
109
101
  if (initialEndDateTime < now)
110
102
  return;
111
103
  }
112
- const job = new Job_1.Job(jobOptions, this.pathJobs, this._pythonPath);
104
+ const job = new Job(jobOptions, this.pathJobs, this._pythonPath);
113
105
  await this._sheduler.add(job.externalData);
114
106
  await this._sheduler.start(jobOptions._id);
115
107
  return job.name;
@@ -130,7 +122,7 @@ class Sheduler {
130
122
  }
131
123
  return true;
132
124
  })
133
- .map((jobOptions) => new Job_1.Job(jobOptions, this.pathJobs, this._pythonPath));
125
+ .map((jobOptions) => new Job(jobOptions, this.pathJobs, this._pythonPath));
134
126
  if (jobs.length == 0) {
135
127
  return;
136
128
  }
@@ -166,9 +158,62 @@ class Sheduler {
166
158
  });
167
159
  }
168
160
  }
169
- exports.Sheduler = Sheduler;
161
+ export class Job {
162
+ constructor(jobOption, pathJobs, pythonPath, defaultScriptName) {
163
+ this.name = jobOption._id;
164
+ this.path = path.join(process.cwd(), "assets", "scriptFlow.js");
165
+ this.interval = jobOption.interval || 0;
166
+ this._pythonPath = pythonPath;
167
+ this._defaultScriptName = defaultScriptName || 'script.py';
168
+ this.init(jobOption, pathJobs);
169
+ }
170
+ get externalData() {
171
+ return {
172
+ name: this.name,
173
+ path: this.path,
174
+ interval: this.interval,
175
+ date: this.date,
176
+ cron: this.cron,
177
+ worker: this.worker,
178
+ };
179
+ }
180
+ init(jobOption, pathJobs) {
181
+ //определение даты начала
182
+ const initialStartDateTime = new Date(jobOption.startDateTime);
183
+ const now = new Date();
184
+ const reserveSeconds = 10;
185
+ let dateStart = initialStartDateTime >
186
+ new Date(now.setSeconds(now.getSeconds() + reserveSeconds))
187
+ ? initialStartDateTime
188
+ : undefined;
189
+ if (dateStart) {
190
+ this.date = dateStart;
191
+ }
192
+ this.worker = {
193
+ workerData: {
194
+ scriptPythonPath: path.join(pathJobs, jobOption._id, this._defaultScriptName),
195
+ pythonPath: this._pythonPath,
196
+ },
197
+ };
198
+ }
199
+ }
200
+ export var JobStatus;
201
+ (function (JobStatus) {
202
+ JobStatus["STOPPED"] = "stopped";
203
+ JobStatus["RUNNING"] = "running";
204
+ JobStatus["WORKING"] = "working";
205
+ JobStatus["ERROR"] = "error";
206
+ })(JobStatus || (JobStatus = {}));
207
+ export var IntervalsJob;
208
+ (function (IntervalsJob) {
209
+ IntervalsJob["SECONDS"] = "seconds";
210
+ IntervalsJob["MINUTES"] = "minutes";
211
+ IntervalsJob["HOURS"] = "hours";
212
+ IntervalsJob["DAYS"] = "days";
213
+ IntervalsJob["MONTHS"] = "months";
214
+ })(IntervalsJob || (IntervalsJob = {}));
170
215
  //utils
171
- exports.months = [
216
+ export const months = [
172
217
  'January',
173
218
  'February',
174
219
  'March',
@@ -182,7 +227,7 @@ exports.months = [
182
227
  'November',
183
228
  'December',
184
229
  ];
185
- exports.weekDays = [
230
+ export const weekDays = [
186
231
  'Monday',
187
232
  'Tuesday',
188
233
  'Wednesday',
@@ -191,37 +236,36 @@ exports.weekDays = [
191
236
  'Saturday',
192
237
  'Sunday',
193
238
  ];
194
- const getInterval = (jobOption) => {
239
+ export const getInterval = (jobOption) => {
195
240
  if ((jobOption.intervalMeasur && jobOption.intervalValue) || jobOption.weekDays || jobOption.yearMonths) {
196
241
  let builder = '';
197
242
  if (jobOption.intervalMeasur && jobOption.intervalValue) {
198
243
  builder = 'every';
199
244
  switch (jobOption.intervalMeasur) {
200
- case types_1.IntervalsJob.SECONDS:
245
+ case IntervalsJob.SECONDS:
201
246
  builder = `${builder} ${jobOption.intervalValue} seconds`;
202
247
  break;
203
- case types_1.IntervalsJob.MINUTES:
248
+ case IntervalsJob.MINUTES:
204
249
  builder = `${builder} ${jobOption.intervalValue} minutes`;
205
250
  break;
206
- case types_1.IntervalsJob.HOURS:
251
+ case IntervalsJob.HOURS:
207
252
  builder = `${builder} ${jobOption.intervalValue} hours`;
208
253
  break;
209
- case types_1.IntervalsJob.DAYS:
254
+ case IntervalsJob.DAYS:
210
255
  builder = `${builder} ${jobOption.intervalValue} day`;
211
256
  break;
212
- case types_1.IntervalsJob.MONTHS:
257
+ case IntervalsJob.MONTHS:
213
258
  builder = `${builder} ${jobOption.intervalValue} month`;
214
259
  break;
215
260
  }
216
261
  }
217
262
  if (jobOption.weekDays && jobOption.weekDays.length > 0) {
218
- builder = `${builder} on ${jobOption.weekDays.map(wd => exports.weekDays[wd - 1]).join(',')}`;
263
+ builder = `${builder} on ${jobOption.weekDays.map(wd => weekDays[wd - 1]).join(',')}`;
219
264
  }
220
265
  if (jobOption.yearMonths && jobOption.yearMonths.length > 0) {
221
- 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`;
222
267
  }
223
268
  return builder;
224
269
  }
225
270
  return;
226
271
  };
227
- exports.getInterval = getInterval;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@easyrpa/sheduler",
3
- "version": "1.0.1",
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",
7
7
  "type": "module",
8
8
  "scripts": {
9
9
  "test": "echo \"Error: no test specified\" && exit 1",
10
- "build": "tsc"
10
+ "build": "rimraf dist && tsc"
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
@@ -30,7 +30,7 @@
30
30
  "bree": "^9.2.9",
31
31
  "crypto-ts": "^1.0.2"
32
32
  },
33
- "keywords": [
33
+ "keywords": [
34
34
  "easyrpa",
35
35
  "sheduler"
36
36
  ],
@@ -38,5 +38,8 @@
38
38
  "publishConfig": {
39
39
  "access": "public",
40
40
  "registry": "https://registry.npmjs.org/"
41
+ },
42
+ "devDependencies": {
43
+ "rimraf": "^6.1.3"
41
44
  }
42
45
  }
package/dist/Job.d.ts DELETED
@@ -1,24 +0,0 @@
1
- import { JobOptionsType, JobType } from "./types";
2
- import { type WorkerOptions } from "node:worker_threads";
3
- export interface IJob {
4
- name: string;
5
- path: string;
6
- interval: number | string;
7
- date?: Date;
8
- cron?: string;
9
- worker?: Partial<WorkerOptions>;
10
- externalData: JobType;
11
- }
12
- export declare class Job implements IJob {
13
- name: string;
14
- path: string;
15
- interval: number | string;
16
- date?: Date;
17
- cron?: string;
18
- worker?: Partial<WorkerOptions>;
19
- _pythonPath: string;
20
- _defaultScriptName: string;
21
- constructor(jobOption: JobOptionsType, pathJobs: string, pythonPath: string, defaultScriptName?: string);
22
- get externalData(): JobType;
23
- private init;
24
- }
package/dist/Job.js DELETED
@@ -1,47 +0,0 @@
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.Job = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- class Job {
9
- constructor(jobOption, pathJobs, pythonPath, defaultScriptName) {
10
- this.name = jobOption._id;
11
- this.path = path_1.default.join(process.cwd(), "assets", "scriptFlow.js");
12
- this.interval = jobOption.interval || 0;
13
- this._pythonPath = pythonPath;
14
- this._defaultScriptName = defaultScriptName || 'script.py';
15
- this.init(jobOption, pathJobs);
16
- }
17
- get externalData() {
18
- return {
19
- name: this.name,
20
- path: this.path,
21
- interval: this.interval,
22
- date: this.date,
23
- cron: this.cron,
24
- worker: this.worker,
25
- };
26
- }
27
- init(jobOption, pathJobs) {
28
- //определение даты начала
29
- const initialStartDateTime = new Date(jobOption.startDateTime);
30
- const now = new Date();
31
- const reserveSeconds = 10;
32
- let dateStart = initialStartDateTime >
33
- new Date(now.setSeconds(now.getSeconds() + reserveSeconds))
34
- ? initialStartDateTime
35
- : undefined;
36
- if (dateStart) {
37
- this.date = dateStart;
38
- }
39
- this.worker = {
40
- workerData: {
41
- scriptPythonPath: path_1.default.join(pathJobs, jobOption._id, this._defaultScriptName),
42
- pythonPath: this._pythonPath,
43
- },
44
- };
45
- }
46
- }
47
- exports.Job = Job;
package/dist/types.d.ts DELETED
@@ -1,54 +0,0 @@
1
- export type JobOptionsType = {
2
- _id: string;
3
- name: string;
4
- status: JobStatus;
5
- logs: JobLogType[];
6
- flow: JobFlowType;
7
- startDateTime: string;
8
- interval?: string;
9
- intervalMeasur?: IntervalsJob;
10
- intervalValue?: number;
11
- weekDays?: number[];
12
- yearMonths?: number[];
13
- endDateTime?: string;
14
- };
15
- export type JobType = {
16
- name: string;
17
- path: string;
18
- interval: number | string;
19
- date?: Date;
20
- cron?: string;
21
- worker?: Partial<WorkerOptions>;
22
- };
23
- export declare enum JobStatus {
24
- STOPPED = "stopped",
25
- RUNNING = "running",
26
- WORKING = "working",
27
- ERROR = "error"
28
- }
29
- export type JobLogType = {
30
- category: 'run' | 'stop' | 'message' | 'workerCreated' | 'workerDeleted';
31
- date: string;
32
- message?: string;
33
- };
34
- export type JobFlowType = {
35
- name: string;
36
- content: string;
37
- };
38
- export declare enum IntervalsJob {
39
- SECONDS = "seconds",
40
- MINUTES = "minutes",
41
- HOURS = "hours",
42
- DAYS = "days",
43
- MONTHS = "months"
44
- }
45
- export type ShedulerLogger = {
46
- info(...args: string[]): void;
47
- log(...args: string[]): void;
48
- error(...args: string[]): void;
49
- warn(...args: string[]): void;
50
- };
51
- export type ShedulerMessageType = {
52
- name: string;
53
- message: unknown;
54
- };
package/dist/types.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IntervalsJob = exports.JobStatus = void 0;
4
- var JobStatus;
5
- (function (JobStatus) {
6
- JobStatus["STOPPED"] = "stopped";
7
- JobStatus["RUNNING"] = "running";
8
- JobStatus["WORKING"] = "working";
9
- JobStatus["ERROR"] = "error";
10
- })(JobStatus || (exports.JobStatus = JobStatus = {}));
11
- var IntervalsJob;
12
- (function (IntervalsJob) {
13
- IntervalsJob["SECONDS"] = "seconds";
14
- IntervalsJob["MINUTES"] = "minutes";
15
- IntervalsJob["HOURS"] = "hours";
16
- IntervalsJob["DAYS"] = "days";
17
- IntervalsJob["MONTHS"] = "months";
18
- })(IntervalsJob || (exports.IntervalsJob = IntervalsJob = {}));