@easyrpa/sheduler 1.0.1 → 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,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
@@ -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.getInterval = exports.weekDays = exports.months = 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,8 +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 types_1 = require("./types");
15
- const Job_1 = require("./Job");
16
14
  class Sheduler {
17
15
  constructor(config, collections) {
18
16
  this._logger = config.logger;
@@ -109,7 +107,7 @@ class Sheduler {
109
107
  if (initialEndDateTime < now)
110
108
  return;
111
109
  }
112
- const job = new Job_1.Job(jobOptions, this.pathJobs, this._pythonPath);
110
+ const job = new Job(jobOptions, this.pathJobs, this._pythonPath);
113
111
  await this._sheduler.add(job.externalData);
114
112
  await this._sheduler.start(jobOptions._id);
115
113
  return job.name;
@@ -130,7 +128,7 @@ class Sheduler {
130
128
  }
131
129
  return true;
132
130
  })
133
- .map((jobOptions) => new Job_1.Job(jobOptions, this.pathJobs, this._pythonPath));
131
+ .map((jobOptions) => new Job(jobOptions, this.pathJobs, this._pythonPath));
134
132
  if (jobs.length == 0) {
135
133
  return;
136
134
  }
@@ -167,6 +165,61 @@ class Sheduler {
167
165
  }
168
166
  }
169
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 = {}));
170
223
  //utils
171
224
  exports.months = [
172
225
  'January',
@@ -197,19 +250,19 @@ const getInterval = (jobOption) => {
197
250
  if (jobOption.intervalMeasur && jobOption.intervalValue) {
198
251
  builder = 'every';
199
252
  switch (jobOption.intervalMeasur) {
200
- case types_1.IntervalsJob.SECONDS:
253
+ case IntervalsJob.SECONDS:
201
254
  builder = `${builder} ${jobOption.intervalValue} seconds`;
202
255
  break;
203
- case types_1.IntervalsJob.MINUTES:
256
+ case IntervalsJob.MINUTES:
204
257
  builder = `${builder} ${jobOption.intervalValue} minutes`;
205
258
  break;
206
- case types_1.IntervalsJob.HOURS:
259
+ case IntervalsJob.HOURS:
207
260
  builder = `${builder} ${jobOption.intervalValue} hours`;
208
261
  break;
209
- case types_1.IntervalsJob.DAYS:
262
+ case IntervalsJob.DAYS:
210
263
  builder = `${builder} ${jobOption.intervalValue} day`;
211
264
  break;
212
- case types_1.IntervalsJob.MONTHS:
265
+ case IntervalsJob.MONTHS:
213
266
  builder = `${builder} ${jobOption.intervalValue} month`;
214
267
  break;
215
268
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@easyrpa/sheduler",
3
- "version": "1.0.1",
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 = {}));