@easyrpa/sheduler 1.0.0 → 1.0.2

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,3 +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
+ };
125
+ export declare const months: string[];
126
+ export declare const weekDays: string[];
127
+ export declare const getInterval: (jobOption: Partial<JobOptionsType>) => string | undefined;
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Sheduler = void 0;
6
+ exports.getInterval = exports.weekDays = exports.months = exports.IntervalsJob = exports.JobStatus = exports.Job = exports.Sheduler = void 0;
7
7
  const bree_1 = __importDefault(require("bree"));
8
8
  const ts_worker_1 = __importDefault(require("@breejs/ts-worker"));
9
9
  bree_1.default.extend(ts_worker_1.default);
@@ -11,7 +11,6 @@ const path_1 = __importDefault(require("path"));
11
11
  const promises_1 = __importDefault(require("fs/promises"));
12
12
  const crypto_ts_1 = require("crypto-ts");
13
13
  const script_creator_1 = require("@easyrpa/script-creator");
14
- const Job_1 = require("./Job");
15
14
  class Sheduler {
16
15
  constructor(config, collections) {
17
16
  this._logger = config.logger;
@@ -108,7 +107,7 @@ class Sheduler {
108
107
  if (initialEndDateTime < now)
109
108
  return;
110
109
  }
111
- const job = new Job_1.Job(jobOptions, this.pathJobs, this._pythonPath);
110
+ const job = new Job(jobOptions, this.pathJobs, this._pythonPath);
112
111
  await this._sheduler.add(job.externalData);
113
112
  await this._sheduler.start(jobOptions._id);
114
113
  return job.name;
@@ -129,7 +128,7 @@ class Sheduler {
129
128
  }
130
129
  return true;
131
130
  })
132
- .map((jobOptions) => new Job_1.Job(jobOptions, this.pathJobs, this._pythonPath));
131
+ .map((jobOptions) => new Job(jobOptions, this.pathJobs, this._pythonPath));
133
132
  if (jobs.length == 0) {
134
133
  return;
135
134
  }
@@ -166,3 +165,116 @@ class Sheduler {
166
165
  }
167
166
  }
168
167
  exports.Sheduler = Sheduler;
168
+ class Job {
169
+ constructor(jobOption, pathJobs, pythonPath, defaultScriptName) {
170
+ this.name = jobOption._id;
171
+ this.path = path_1.default.join(process.cwd(), "assets", "scriptFlow.js");
172
+ this.interval = jobOption.interval || 0;
173
+ this._pythonPath = pythonPath;
174
+ this._defaultScriptName = defaultScriptName || 'script.py';
175
+ this.init(jobOption, pathJobs);
176
+ }
177
+ get externalData() {
178
+ return {
179
+ name: this.name,
180
+ path: this.path,
181
+ interval: this.interval,
182
+ date: this.date,
183
+ cron: this.cron,
184
+ worker: this.worker,
185
+ };
186
+ }
187
+ init(jobOption, pathJobs) {
188
+ //определение даты начала
189
+ const initialStartDateTime = new Date(jobOption.startDateTime);
190
+ const now = new Date();
191
+ const reserveSeconds = 10;
192
+ let dateStart = initialStartDateTime >
193
+ new Date(now.setSeconds(now.getSeconds() + reserveSeconds))
194
+ ? initialStartDateTime
195
+ : undefined;
196
+ if (dateStart) {
197
+ this.date = dateStart;
198
+ }
199
+ this.worker = {
200
+ workerData: {
201
+ scriptPythonPath: path_1.default.join(pathJobs, jobOption._id, this._defaultScriptName),
202
+ pythonPath: this._pythonPath,
203
+ },
204
+ };
205
+ }
206
+ }
207
+ exports.Job = Job;
208
+ var JobStatus;
209
+ (function (JobStatus) {
210
+ JobStatus["STOPPED"] = "stopped";
211
+ JobStatus["RUNNING"] = "running";
212
+ JobStatus["WORKING"] = "working";
213
+ JobStatus["ERROR"] = "error";
214
+ })(JobStatus || (exports.JobStatus = JobStatus = {}));
215
+ var IntervalsJob;
216
+ (function (IntervalsJob) {
217
+ IntervalsJob["SECONDS"] = "seconds";
218
+ IntervalsJob["MINUTES"] = "minutes";
219
+ IntervalsJob["HOURS"] = "hours";
220
+ IntervalsJob["DAYS"] = "days";
221
+ IntervalsJob["MONTHS"] = "months";
222
+ })(IntervalsJob || (exports.IntervalsJob = IntervalsJob = {}));
223
+ //utils
224
+ exports.months = [
225
+ 'January',
226
+ 'February',
227
+ 'March',
228
+ 'April',
229
+ 'May',
230
+ 'June',
231
+ 'July',
232
+ 'August',
233
+ 'September',
234
+ 'October',
235
+ 'November',
236
+ 'December',
237
+ ];
238
+ exports.weekDays = [
239
+ 'Monday',
240
+ 'Tuesday',
241
+ 'Wednesday',
242
+ 'Thursday',
243
+ 'Friday',
244
+ 'Saturday',
245
+ 'Sunday',
246
+ ];
247
+ const getInterval = (jobOption) => {
248
+ if ((jobOption.intervalMeasur && jobOption.intervalValue) || jobOption.weekDays || jobOption.yearMonths) {
249
+ let builder = '';
250
+ if (jobOption.intervalMeasur && jobOption.intervalValue) {
251
+ builder = 'every';
252
+ switch (jobOption.intervalMeasur) {
253
+ case IntervalsJob.SECONDS:
254
+ builder = `${builder} ${jobOption.intervalValue} seconds`;
255
+ break;
256
+ case IntervalsJob.MINUTES:
257
+ builder = `${builder} ${jobOption.intervalValue} minutes`;
258
+ break;
259
+ case IntervalsJob.HOURS:
260
+ builder = `${builder} ${jobOption.intervalValue} hours`;
261
+ break;
262
+ case IntervalsJob.DAYS:
263
+ builder = `${builder} ${jobOption.intervalValue} day`;
264
+ break;
265
+ case IntervalsJob.MONTHS:
266
+ builder = `${builder} ${jobOption.intervalValue} month`;
267
+ break;
268
+ }
269
+ }
270
+ if (jobOption.weekDays && jobOption.weekDays.length > 0) {
271
+ builder = `${builder} on ${jobOption.weekDays.map(wd => exports.weekDays[wd - 1]).join(',')}`;
272
+ }
273
+ if (jobOption.yearMonths && jobOption.yearMonths.length > 0) {
274
+ builder = `${builder} of ${jobOption.yearMonths.map(ym => exports.months[ym - 1]).join(',')} month`;
275
+ }
276
+ return builder;
277
+ }
278
+ return;
279
+ };
280
+ exports.getInterval = getInterval;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@easyrpa/sheduler",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
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 = {}));