exodus-framework 2.0.795 → 2.0.797

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 (48) hide show
  1. package/lib/app/core.d.ts +2 -0
  2. package/lib/app/core.d.ts.map +1 -1
  3. package/lib/app/core.js +7 -1
  4. package/lib/app/exodus.d.ts.map +1 -1
  5. package/lib/app/exodus.js +3 -8
  6. package/lib/app/service.d.ts +19 -5
  7. package/lib/app/service.d.ts.map +1 -1
  8. package/lib/app/service.js +55 -11
  9. package/lib/contracts/service.d.ts +9 -0
  10. package/lib/contracts/service.d.ts.map +1 -1
  11. package/lib/contracts/service.js +11 -1
  12. package/lib/services/index.d.ts +1 -0
  13. package/lib/services/index.d.ts.map +1 -1
  14. package/lib/services/index.js +9 -1
  15. package/lib/services/task/TaskServiceBase.d.ts +3 -3
  16. package/lib/services/task/TaskServiceBase.d.ts.map +1 -1
  17. package/lib/services/task/TaskServiceBase.js +4 -1
  18. package/lib/services/task/queue/QueueService.d.ts +4 -3
  19. package/lib/services/task/queue/QueueService.d.ts.map +1 -1
  20. package/lib/services/task/queue/QueueService.js +14 -10
  21. package/lib/services/task/queue/QueueTask.d.ts +10 -1
  22. package/lib/services/task/queue/QueueTask.d.ts.map +1 -1
  23. package/lib/services/task/queue/QueueTask.js +42 -0
  24. package/lib/services/task/scheduler/SchedulerService.d.ts +4 -3
  25. package/lib/services/task/scheduler/SchedulerService.d.ts.map +1 -1
  26. package/lib/services/task/scheduler/SchedulerService.js +16 -15
  27. package/lib/services/task/scheduler/SchedulerTask.d.ts +29 -1
  28. package/lib/services/task/scheduler/SchedulerTask.d.ts.map +1 -1
  29. package/lib/services/task/scheduler/SchedulerTask.js +137 -0
  30. package/lib/services/test.d.ts +11 -0
  31. package/lib/services/test.d.ts.map +1 -0
  32. package/lib/services/test.js +27 -0
  33. package/lib/tasks/index.d.ts +2 -0
  34. package/lib/tasks/index.d.ts.map +1 -0
  35. package/lib/tasks/index.js +16 -0
  36. package/lib/tasks/queue/index.d.ts +2 -0
  37. package/lib/tasks/queue/index.d.ts.map +1 -0
  38. package/lib/tasks/queue/index.js +13 -0
  39. package/lib/tasks/queue/teste.d.ts +9 -0
  40. package/lib/tasks/queue/teste.d.ts.map +1 -0
  41. package/lib/tasks/queue/teste.js +19 -0
  42. package/lib/tasks/schedule/index.d.ts +1 -0
  43. package/lib/tasks/schedule/index.d.ts.map +1 -0
  44. package/lib/tasks/schedule/index.js +1 -0
  45. package/lib/tasks/schedule/teste.d.ts +21 -0
  46. package/lib/tasks/schedule/teste.d.ts.map +1 -0
  47. package/lib/tasks/schedule/teste.js +58 -0
  48. package/package.json +1 -1
package/lib/app/core.d.ts CHANGED
@@ -28,6 +28,8 @@ declare abstract class Core {
28
28
  sendMessageToMaster(eventKey: string, data: any): void;
29
29
  static getVersion(): string | undefined;
30
30
  protected getCluster(): Worker;
31
+ protected getClusterCount(): number;
32
+ protected getClusters(): NodeJS.Dict<Worker>;
31
33
  static setSettings(settings: CoreSettings): void;
32
34
  static getSettings(): CoreSettings;
33
35
  isCluster(): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/app/core.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAI1C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,YAAY,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAW7D,uBAAe,IAAI;IAKL,SAAS,CAAC,QAAQ;IAJ9B,MAAM,CAAC,QAAQ,eAAsB;IACrC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAS;IACjC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAS;gBAEZ,QAAQ,UAAQ;IAK/B,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE,YAAuB;IA4CtD,OAAO,CAAC,IAAI;I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
94
  }
95
95
  _cluster.default.on('exit', (worker, _code, _signal) => {
96
96
  this.log(`Cluster ${worker.process.pid} foi encerrado`, 'warning');
97
- this.clusterExit(worker, _code, _signal);
98
97
  if (Core.settings.getAppication().clustersRestarts) {
99
98
  this.log(`Reiniciando cluster`, 'warning');
100
99
  _cluster.default.fork();
@@ -107,6 +106,7 @@ class Core {
107
106
  if (worker) {
108
107
  worker.setMaxListeners(20);
109
108
  worker.on('message', message => this.masterReceiveMessage(worker, message));
109
+ worker.on('exit', (code, signal) => this.clusterExit(worker, code, signal));
110
110
  }
111
111
  }
112
112
  }
@@ -216,6 +216,12 @@ class Core {
216
216
  getCluster() {
217
217
  return _cluster.default.worker;
218
218
  }
219
+ getClusterCount() {
220
+ return Core.settings.getAppication().clusters;
221
+ }
222
+ getClusters() {
223
+ return _cluster.default.workers;
224
+ }
219
225
 
220
226
  //#Setters
221
227
  static setSettings(settings) {
@@ -1 +1 @@
1
- {"version":3,"file":"exodus.d.ts","sourceRoot":"","sources":["../../src/app/exodus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,OAAO,EAAE,MAAM,GAAG,CAAC;AAC1C,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC1B,OAAO,YAAY,MAAM,YAAY,CAAC;AAStC,cAAM,MAAO,SAAQ,IAAI;IACvB,OAAO,CAAC,QAAQ,CAAY;gBAGhB,QAAQ,EAAE,YAAY;IAKlC,SAAS,CAAC,MAAM,IAAI,IAAI;IAIlB,KAAK;IAWJ,QAAQ,CAAC,OAAO,EAAE,OAAO,OAAO;IAIjC,YAAY;CAwBnB;AACD,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"exodus.d.ts","sourceRoot":"","sources":["../../src/app/exodus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,OAAO,EAAE,MAAM,GAAG,CAAC;AAC1C,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC1B,OAAO,YAAY,MAAM,YAAY,CAAC;AAStC,cAAM,MAAO,SAAQ,IAAI;IACvB,OAAO,CAAC,QAAQ,CAAY;gBAGhB,QAAQ,EAAE,YAAY;IAMlC,SAAS,CAAC,MAAM,IAAI,IAAI;IAIlB,KAAK;IAWJ,QAAQ,CAAC,OAAO,EAAE,OAAO,OAAO;IAIjC,YAAY;CAgBnB;AACD,eAAe,MAAM,CAAC"}
package/lib/app/exodus.js CHANGED
@@ -21,9 +21,10 @@ class Exodus extends _core.default {
21
21
  constructor(settings) {
22
22
  super(true); //! is system init
23
23
  _core.default.setSettings(settings);
24
+ this.services = [];
24
25
  }
25
26
  onInit() {
26
- this.services = [];
27
+ // system inited
27
28
  }
28
29
  async start() {
29
30
  if (this.isMaster()) {
@@ -42,13 +43,7 @@ class Exodus extends _core.default {
42
43
  async initServices() {
43
44
  for (const service of this.services) {
44
45
  try {
45
- await service.onServiceInit();
46
- if (this.isMaster()) {
47
- await service.onServiceMasterInit();
48
- }
49
- if (this.isCluster()) {
50
- await service.onServiceClusterInit();
51
- }
46
+ await service.serviceInit();
52
47
  } catch (error) {
53
48
  new _.ErrorHandler(`Erro on starting service: ${service.constructor.name} | reason: ${error.message || 'unknow'}`, error);
54
49
  this.log('Não foi possível iniciar os serviços', 'warning');
@@ -1,20 +1,34 @@
1
1
  import { Worker } from 'cluster';
2
+ import { EventEmitter } from 'stream';
2
3
  import { StaticSingleton } from '../contracts';
3
- import Singleton from './singleton';
4
4
  import { TClusterBroadCastMessage } from '../contracts/core';
5
- declare abstract class Service<E extends Record<string, any> = any, D = any> extends Singleton {
6
- protected serviceName: string;
5
+ import Singleton from './singleton';
6
+ import { eEventCommunication, TMappedEventCommunicationHandlers } from '../contracts/service';
7
+ declare abstract class Service<D = any> extends Singleton {
8
+ private eventCommunication;
7
9
  constructor();
10
+ serviceInit(): Promise<void>;
8
11
  onServiceInit(): Promise<void>;
9
12
  onServiceMasterInit(): Promise<void>;
10
13
  onServiceClusterInit(): Promise<void>;
11
14
  protected sendToServiceCluster(clusterId: number, event: string, data: D): void;
12
15
  protected sendToServiceMaster(event: string, data: D): void;
13
- protected onMasterReceiveMessage(worker: Worker, message: TClusterBroadCastMessage): void;
14
- protected onClusterReceiveMessage(message: TClusterBroadCastMessage): void;
15
16
  protected onServiceMasterReceived(_worker: Worker, _eventKey: string, _data: any): void;
16
17
  protected onServiceClusterReceived(_eventKey: string, _data: any): void;
17
18
  static getService<S extends Singleton>(this: StaticSingleton<S>): S;
18
19
  }
19
20
  export default Service;
21
+ export declare class EventCommunicationModule<TransportData = any> extends Singleton {
22
+ protected serviceName: string;
23
+ emitter: EventEmitter;
24
+ constructor(serviceName: string);
25
+ sendToServiceCluster(clusterId: number, event: string, data: TransportData): void;
26
+ sendToServiceMaster(event: string, data: TransportData): void;
27
+ protected onMasterReceiveMessage(worker: Worker, message: TClusterBroadCastMessage): void;
28
+ protected onClusterReceiveMessage(message: TClusterBroadCastMessage): void;
29
+ protected onServiceMasterReceived(worker: Worker, eventKey: string, data: TransportData): void;
30
+ protected onServiceClusterReceived(eventKey: string, data: TransportData): void;
31
+ on<T extends eEventCommunication>(key: T, handle: TMappedEventCommunicationHandlers[T]): void;
32
+ off<T extends eEventCommunication>(key: T, handle: TMappedEventCommunicationHandlers[T]): void;
33
+ }
20
34
  //# sourceMappingURL=service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/app/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAY7D,uBAAe,OAAO,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,CAAE,SAAQ,SAAS;IACpF,SAAS,CAAC,WAAW,EAAE,MAAM,CAAC;;IAMjB,aA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E,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,iCAAiC,CAAC,CAAC,CAAC;CAG/F"}
@@ -3,8 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.default = exports.EventCommunicationModule = void 0;
7
+ var _stream = require("stream");
7
8
  var _singleton = _interopRequireDefault(require("./singleton"));
9
+ var _service = require("../contracts/service");
8
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
11
  /**
10
12
  * Classe base de Serviços
@@ -17,10 +19,21 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
17
19
  * @template S
18
20
  */
19
21
  class Service extends _singleton.default {
20
- serviceName;
22
+ eventCommunication;
21
23
  constructor() {
22
24
  super();
23
- this.serviceName = this.constructor.name;
25
+ this.eventCommunication = new EventCommunicationModule(this.constructor.name);
26
+ }
27
+ async serviceInit() {
28
+ this.eventCommunication.on(_service.eEventCommunication.RECEIVED_CLUSTER_MESSAGE, this.onServiceMasterReceived.bind(this));
29
+ this.eventCommunication.on(_service.eEventCommunication.RECEIVED_MASTER_MESSAGE, this.onClusterReceiveMessage.bind(this));
30
+ await this.onServiceInit();
31
+ if (this.isMaster()) {
32
+ await this.onServiceMasterInit();
33
+ }
34
+ if (this.isCluster()) {
35
+ await this.onServiceClusterInit();
36
+ }
24
37
  }
25
38
  async onServiceInit() {
26
39
  return;
@@ -31,6 +44,30 @@ class Service extends _singleton.default {
31
44
  async onServiceClusterInit() {
32
45
  return;
33
46
  }
47
+ sendToServiceCluster(clusterId, event, data) {
48
+ this.eventCommunication.sendMessageToCluster(clusterId, event, data);
49
+ }
50
+ sendToServiceMaster(event, data) {
51
+ this.eventCommunication.sendMessageToMaster(event, data);
52
+ }
53
+ onServiceMasterReceived(_worker, _eventKey, _data) {
54
+ return;
55
+ }
56
+ onServiceClusterReceived(_eventKey, _data) {
57
+ return;
58
+ }
59
+ static getService() {
60
+ return this.singleton();
61
+ }
62
+ }
63
+ var _default = exports.default = Service;
64
+ class EventCommunicationModule extends _singleton.default {
65
+ emitter;
66
+ constructor(serviceName) {
67
+ super();
68
+ this.serviceName = serviceName;
69
+ this.emitter = new _stream.EventEmitter();
70
+ }
34
71
  sendToServiceCluster(clusterId, event, data) {
35
72
  const key = `${this.serviceName}_${event}`;
36
73
  this.sendMessageToCluster(clusterId, key, data);
@@ -39,24 +76,31 @@ class Service extends _singleton.default {
39
76
  const key = `${this.serviceName}_${event}`;
40
77
  this.sendMessageToMaster(key, data);
41
78
  }
79
+
80
+ //#Non Muted
42
81
  onMasterReceiveMessage(worker, message) {
43
82
  if (!message.eventKey.includes(this.serviceName)) return;
44
83
  const key = message.eventKey.replace(this.serviceName + '_', '');
45
84
  this.onServiceMasterReceived(worker, key, message.data);
46
85
  }
47
86
  onClusterReceiveMessage(message) {
48
- if (!message.eventKey.includes(this.constructor.name)) return;
87
+ if (!message.eventKey.includes(this.serviceName)) return;
49
88
  const key = message.eventKey.replace(this.serviceName + '_', '');
50
89
  this.onServiceClusterReceived(key, message.data);
51
90
  }
52
- onServiceMasterReceived(_worker, _eventKey, _data) {
53
- return;
91
+
92
+ //# Muted
93
+ onServiceMasterReceived(worker, eventKey, data) {
94
+ this.emitter.emit(_service.eEventCommunication.RECEIVED_CLUSTER_MESSAGE, worker, eventKey, data);
54
95
  }
55
- onServiceClusterReceived(_eventKey, _data) {
56
- return;
96
+ onServiceClusterReceived(eventKey, data) {
97
+ this.emitter.emit(_service.eEventCommunication.RECEIVED_MASTER_MESSAGE, eventKey, data);
57
98
  }
58
- static getService() {
59
- return this.singleton();
99
+ on(key, handle) {
100
+ this.emitter.on(key, handle);
101
+ }
102
+ off(key, handle) {
103
+ this.emitter.off(key, handle);
60
104
  }
61
105
  }
62
- var _default = exports.default = Service;
106
+ exports.EventCommunicationModule = EventCommunicationModule;
@@ -1 +1,10 @@
1
+ import { Worker } from 'cluster';
2
+ export declare enum eEventCommunication {
3
+ RECEIVED_MASTER_MESSAGE = "received.master.message",
4
+ RECEIVED_CLUSTER_MESSAGE = "received.cluster.message"
5
+ }
6
+ export type TMappedEventCommunicationHandlers<TransportData = any> = {
7
+ [eEventCommunication.RECEIVED_CLUSTER_MESSAGE]: (worker: Worker, eventKey: string, data: TransportData) => void;
8
+ [eEventCommunication.RECEIVED_MASTER_MESSAGE]: (eventKey: string, data: TransportData) => void;
9
+ };
1
10
  //# sourceMappingURL=service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/contracts/service.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/contracts/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,oBAAY,mBAAmB;IAC7B,uBAAuB,4BAA4B;IACnD,wBAAwB,6BAA6B;CACtD;AACD,MAAM,MAAM,iCAAiC,CAAC,aAAa,GAAG,GAAG,IAAI;IACnE,CAAC,mBAAmB,CAAC,wBAAwB,CAAC,EAAE,CAC9C,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,aAAa,KAChB,IAAI,CAAC;IACV,CAAC,mBAAmB,CAAC,uBAAuB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC;CAChG,CAAC"}
@@ -1 +1,11 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.eEventCommunication = void 0;
7
+ let eEventCommunication = exports.eEventCommunication = /*#__PURE__*/function (eEventCommunication) {
8
+ eEventCommunication["RECEIVED_MASTER_MESSAGE"] = "received.master.message";
9
+ eEventCommunication["RECEIVED_CLUSTER_MESSAGE"] = "received.cluster.message";
10
+ return eEventCommunication;
11
+ }({});
@@ -7,5 +7,6 @@ export { default as SocketIOService } from './socket';
7
7
  export { default as SecurityService } from './security';
8
8
  export { default as LogService } from './log';
9
9
  export { default as EcosystemService } from './ecosystem';
10
+ export { default as TestService } from './test';
10
11
  export * from './task';
11
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAC;AAChD,cAAc,QAAQ,CAAC"}
@@ -12,7 +12,8 @@ var _exportNames = {
12
12
  SocketIOService: true,
13
13
  SecurityService: true,
14
14
  LogService: true,
15
- EcosystemService: true
15
+ EcosystemService: true,
16
+ TestService: true
16
17
  };
17
18
  Object.defineProperty(exports, "EcosystemService", {
18
19
  enumerable: true,
@@ -68,6 +69,12 @@ Object.defineProperty(exports, "SocketIOService", {
68
69
  return _socket.default;
69
70
  }
70
71
  });
72
+ Object.defineProperty(exports, "TestService", {
73
+ enumerable: true,
74
+ get: function () {
75
+ return _test.default;
76
+ }
77
+ });
71
78
  var _express = _interopRequireDefault(require("./express"));
72
79
  var _file = _interopRequireDefault(require("./file"));
73
80
  var _rabitmq = _interopRequireDefault(require("./rabitmq"));
@@ -77,6 +84,7 @@ var _socket = _interopRequireDefault(require("./socket"));
77
84
  var _security = _interopRequireDefault(require("./security"));
78
85
  var _log = _interopRequireDefault(require("./log"));
79
86
  var _ecosystem = _interopRequireDefault(require("./ecosystem"));
87
+ var _test = _interopRequireDefault(require("./test"));
80
88
  var _task = require("./task");
81
89
  Object.keys(_task).forEach(function (key) {
82
90
  if (key === "default" || key === "__esModule") return;
@@ -1,8 +1,8 @@
1
1
  import { Service } from '../../app';
2
- declare abstract class TaskServiceBase extends Service {
3
- protected jobsPath: string;
4
- abstract registerJob(...args: any[]): Promise<void>;
2
+ declare abstract class TaskServiceBase<T> extends Service {
3
+ protected tasks: T[];
5
4
  static setTaskPath(path: string): void;
5
+ static registerTask<T>(task: T): void;
6
6
  }
7
7
  export default TaskServiceBase;
8
8
  //# sourceMappingURL=TaskServiceBase.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TaskServiceBase.d.ts","sourceRoot":"","sources":["../../../src/services/task/TaskServiceBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,uBAAe,eAAgB,SAAQ,OAAO;IAC5C,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE3B,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAEnD,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM;CAGhC;AAED,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"TaskServiceBase.d.ts","sourceRoot":"","sources":["../../../src/services/task/TaskServiceBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,uBAAe,eAAe,CAAC,CAAC,CAAE,SAAQ,OAAO;IAC/C,SAAS,CAAC,KAAK,EAAE,CAAC,EAAE,CAAM;IAE1B,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM;IAI/B,MAAM,CAAC,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;CAG/B;AAED,eAAe,eAAe,CAAC"}
@@ -6,9 +6,12 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _app = require("../../app");
8
8
  class TaskServiceBase extends _app.Service {
9
- jobsPath;
9
+ tasks = [];
10
10
  static setTaskPath(path) {
11
11
  this.getService().jobsPath = path;
12
12
  }
13
+ static registerTask(task) {
14
+ this.getService().tasks.push(task);
15
+ }
13
16
  }
14
17
  var _default = exports.default = TaskServiceBase;
@@ -1,10 +1,11 @@
1
1
  import TaskServiceBase from '../TaskServiceBase';
2
2
  import QueueTask from './QueueTask';
3
- declare class QueueTaskService extends TaskServiceBase {
4
- private jobs;
3
+ declare class QueueTaskService extends TaskServiceBase<QueueTask<any> & {
4
+ new (): QueueTask<any>;
5
+ }> {
5
6
  private connection;
7
+ private jobsPath;
6
8
  onServiceInit(): Promise<void>;
7
- registerJob(job: QueueTask<any>): Promise<void>;
8
9
  private importAllJobs;
9
10
  private processAllJobs;
10
11
  startTask(task: QueueTask<any>): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"QueueService.d.ts","sourceRoot":"","sources":["../../../../src/services/task/queue/QueueService.ts"],"names":[],"mappings":"AAIA,OAAO,eAAe,MAAM,oBAAoB,CAAC;AACjD,OAAO,SAAS,MAAM,aAAa,CAAC;AAGpC,cAAM,gBAAiB,SAAQ,eAAe;IAC5C,OAAO,CAAC,IAAI,CAAmB;IAC/B,OAAO,CAAC,UAAU,CAAoB;IAEhC,aAAa;IAeN,WAAW,CAAC,GAAG,EAAE,SAAS,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;YAI9C,aAAa;YAUb,cAAc;IAMf,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,GAAG,CAAC;CAiB5C;AAED,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"QueueService.d.ts","sourceRoot":"","sources":["../../../../src/services/task/queue/QueueService.ts"],"names":[],"mappings":"AAIA,OAAO,eAAe,MAAM,oBAAoB,CAAC;AACjD,OAAO,SAAS,MAAM,aAAa,CAAC;AAGpC,cAAM,gBAAiB,SAAQ,eAAe,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG;IAAE,QAAQ,SAAS,CAAC,GAAG,CAAC,CAAA;CAAE,CAAC;IACzF,OAAO,CAAC,UAAU,CAAoB;IACtC,OAAO,CAAC,QAAQ,CAAM;IAEhB,aAAa;YAmBL,aAAa;YAUb,cAAc;IAOf,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,GAAG,CAAC;CAiB5C;AAED,eAAe,gBAAgB,CAAC"}
@@ -11,23 +11,26 @@ var _TaskServiceBase = _interopRequireDefault(require("../TaskServiceBase"));
11
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
12
  //* Queue
13
13
  class QueueTaskService extends _TaskServiceBase.default {
14
- jobs;
15
14
  connection;
15
+ jobsPath = '';
16
16
  async onServiceInit() {
17
- this.jobs = [];
18
17
  this.connection = {
19
18
  host: _app.Core.settings.getCache().host,
20
19
  port: Number(_app.Core.settings.getCache().port),
21
20
  password: _app.Core.settings.getCache().password
22
21
  };
23
22
  this.log('Initializing jobs...', 'info');
24
- await this.importAllJobs();
25
23
  await this.processAllJobs();
26
24
  this.log('All jobs initializeds...', 'info');
27
25
  }
28
- async registerJob(job) {
29
- this.jobs.push(job);
30
- }
26
+
27
+ /**
28
+ * Importa os arquivos de task
29
+ * !no modo cluster, é lançado erro PIPE após todos os clusters tentar acessar o mesmo arquivo
30
+ * @deprecated
31
+ * @private
32
+ * @memberof QueueTaskService
33
+ */
31
34
  async importAllJobs() {
32
35
  if (!(0, _fs.existsSync)(this.jobsPath)) (0, _fs.mkdirSync)(this.jobsPath, {
33
36
  recursive: true
@@ -35,12 +38,13 @@ class QueueTaskService extends _TaskServiceBase.default {
35
38
  for (const handlerFile of (0, _fs.readdirSync)(this.jobsPath)) {
36
39
  const job = require(`${this.jobsPath}/${handlerFile}`).default;
37
40
  const jobInstance = job.singleton();
38
- this.jobs.push(jobInstance);
41
+ this.tasks.push(jobInstance);
39
42
  }
40
43
  }
41
44
  async processAllJobs() {
42
- for (const job of this.jobs) {
43
- this.startTask(job);
45
+ for (const task of this.tasks) {
46
+ const instanceTask = new task();
47
+ this.startTask(instanceTask);
44
48
  }
45
49
  }
46
50
  async startTask(task) {
@@ -54,7 +58,7 @@ class QueueTaskService extends _TaskServiceBase.default {
54
58
  task.setQueue(queue);
55
59
  task.setWorker(worker);
56
60
  task.taskInit();
57
- this.log(`Job '${task.getName()}' started...`, 'warning');
61
+ this.log(`Task '${task.getName()}' started...`, 'warning');
58
62
  }
59
63
  }
60
64
  var _default = exports.default = QueueTaskService;
@@ -3,6 +3,7 @@ import { Singleton } from '../../../app';
3
3
  declare abstract class QueueTask<DataType, ResultType = any, NameType extends string = string> extends Singleton {
4
4
  protected queue: Queue;
5
5
  protected worker: Worker;
6
+ private eventCommunication;
6
7
  addJob(data: DataType): Promise<void>;
7
8
  getQueue(): Queue<any, any, string>;
8
9
  setQueue(queue: Queue): void;
@@ -10,11 +11,19 @@ declare abstract class QueueTask<DataType, ResultType = any, NameType extends st
10
11
  setWorker(worker: Worker): void;
11
12
  taskInit(): Promise<void>;
12
13
  execute(job: Job<DataType, ResultType, NameType>, token: string): void;
14
+ protected sendToServiceCluster(clusterId: number, event: string, data: DataType): void;
15
+ protected sendToServiceMaster(event: string, data: DataType): void;
13
16
  onTaskInit(): Promise<void> | void;
17
+ onTaskClusterInit(): Promise<void> | void;
18
+ onTaskMasterInit(): Promise<void> | void;
19
+ protected onServiceMasterReceived(_worker: Worker, _eventKey: string, _data: DataType): void;
20
+ protected onServiceClusterReceived(_eventKey: string, _data: DataType): void;
21
+ onClusterExecute(_job: Job<DataType, ResultType, NameType>, _token?: string): Promise<void> | void;
22
+ onMasterExecute(_job: Job<DataType, ResultType, NameType>, _token?: string): Promise<void> | void;
23
+ onExecute(_job: Job<DataType, ResultType, NameType>, _token?: string): Promise<void> | void;
14
24
  onNewJob(_data: DataType): Promise<void> | void;
15
25
  getActive(): boolean;
16
26
  abstract getName(): string;
17
- abstract onExecute(_job: Job<DataType, ResultType, NameType>, _token?: string): Promise<ResultType> | ResultType;
18
27
  }
19
28
  export default QueueTask;
20
29
  //# sourceMappingURL=QueueTask.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"QueueTask.d.ts","sourceRoot":"","sources":["../../../../src/services/task/queue/QueueTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,uBAAe,SAAS,CACtB,QAAQ,EACR,UAAU,GAAG,GAAG,E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AC,GAAG,IAAI;IAIhB,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAG/C,SAAS,IAAI,OAAO;IAI3B,QAAQ,CAAC,OAAO,IAAI,MAAM;CAC3B;AAED,eAAe,SAAS,CAAC"}
@@ -5,9 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _app = require("../../../app");
8
+ var _service = require("../../../app/service");
8
9
  class QueueTask extends _app.Singleton {
9
10
  queue;
10
11
  worker;
12
+ eventCommunication;
11
13
  async addJob(data) {
12
14
  await this.queue.add(this.getName(), data);
13
15
  this.onNewJob(data);
@@ -26,16 +28,56 @@ class QueueTask extends _app.Singleton {
26
28
  this.worker = worker;
27
29
  }
28
30
  async taskInit() {
31
+ this.eventCommunication = new _service.EventCommunicationModule(this.constructor.name);
29
32
  this.onTaskInit();
33
+ if (this.isMaster()) {
34
+ this.onTaskMasterInit();
35
+ }
36
+ if (this.isCluster()) {
37
+ this.onTaskClusterInit();
38
+ }
30
39
  }
31
40
  execute(job, token) {
32
41
  this.onExecute(job, token);
42
+ if (this.isCluster()) {
43
+ this.onClusterExecute(job, token);
44
+ }
45
+ if (this.isMaster()) {
46
+ this.onMasterExecute(job, token);
47
+ }
48
+ }
49
+ sendToServiceCluster(clusterId, event, data) {
50
+ this.eventCommunication.sendMessageToCluster(clusterId, event, data);
51
+ }
52
+ sendToServiceMaster(event, data) {
53
+ this.eventCommunication.sendMessageToMaster(event, data);
33
54
  }
34
55
 
35
56
  //# Muted Methods
36
57
  onTaskInit() {
37
58
  return;
38
59
  }
60
+ onTaskClusterInit() {
61
+ return;
62
+ }
63
+ onTaskMasterInit() {
64
+ return;
65
+ }
66
+ onServiceMasterReceived(_worker, _eventKey, _data) {
67
+ return;
68
+ }
69
+ onServiceClusterReceived(_eventKey, _data) {
70
+ return;
71
+ }
72
+ onClusterExecute(_job, _token) {
73
+ return;
74
+ }
75
+ onMasterExecute(_job, _token) {
76
+ return;
77
+ }
78
+ onExecute(_job, _token) {
79
+ return;
80
+ }
39
81
  onNewJob(_data) {
40
82
  return;
41
83
  }
@@ -1,9 +1,10 @@
1
1
  import TaskServiceBase from '../TaskServiceBase';
2
2
  import ScheduleTask from './SchedulerTask';
3
- declare class SchedulerTaskService extends TaskServiceBase {
4
- private jobs;
3
+ declare class SchedulerTaskService extends TaskServiceBase<ScheduleTask & {
4
+ new (): ScheduleTask;
5
+ }> {
6
+ private jobsPath;
5
7
  onServiceInit(): Promise<void>;
6
- registerJob(job: ScheduleTask): Promise<void>;
7
8
  private importAllJobs;
8
9
  private processAllJobs;
9
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SchedulerService.d.ts","sourceRoot":"","sources":["../../../../src/services/task/scheduler/SchedulerService.ts"],"names":[],"mappings":"AAGA,OAAO,eAAe,MAAM,oBAAoB,CAAC;AACjD,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAE3C,cAAM,oBAAqB,SAAQ,eAAe;IAChD,OAAO,CAAC,IAAI,CAAiB;IAEvB,aAAa;IAYN,WAAW,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;YAG5C,aAAa;YAcb,cAAc;CAQ7B;AAED,eAAe,oBAAoB,CAAC"}
1
+ {"version":3,"file":"SchedulerService.d.ts","sourceRoot":"","sources":["../../../../src/services/task/scheduler/SchedulerService.ts"],"names":[],"mappings":"AAGA,OAAO,eAAe,MAAM,oBAAoB,CAAC;AACjD,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAE3C,cAAM,oBAAqB,SAAQ,eAAe,CAAC,YAAY,GAAG;IAAE,QAAQ,YAAY,CAAA;CAAE,CAAC;IACzF,OAAO,CAAC,QAAQ,CAAM;IAEhB,aAAa;YAaL,aAAa;YAcb,cAAc;CAS7B;AAED,eAAe,oBAAoB,CAAC"}
@@ -10,20 +10,20 @@ var _app = require("../../../app");
10
10
  var _TaskServiceBase = _interopRequireDefault(require("../TaskServiceBase"));
11
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
12
  class SchedulerTaskService extends _TaskServiceBase.default {
13
- jobs;
13
+ jobsPath = '';
14
14
  async onServiceInit() {
15
- if (!this.jobsPath) {
16
- return this.log('Tasks file path not found!', 'danger');
17
- }
18
- this.jobs = [];
19
15
  this.log('Initializing jobs...', 'info');
20
- await this.importAllJobs();
21
16
  await this.processAllJobs();
22
17
  this.log('All jobs initializeds...', 'info');
23
18
  }
24
- async registerJob(job) {
25
- this.jobs.push(job);
26
- }
19
+
20
+ /**
21
+ * Importa os arquivos de task
22
+ * !no modo cluster, é lançado erro PIPE após todos os clusters tentar acessar o mesmo arquivo
23
+ * @deprecated
24
+ * @private
25
+ * @memberof QueueTaskService
26
+ */
27
27
  async importAllJobs() {
28
28
  if (!(0, _fs.existsSync)(this.jobsPath)) (0, _fs.mkdirSync)(this.jobsPath, {
29
29
  recursive: true
@@ -32,18 +32,19 @@ class SchedulerTaskService extends _TaskServiceBase.default {
32
32
  try {
33
33
  const job = require(`${this.jobsPath}/${handlerFile}`).default;
34
34
  const jobInstance = job.singleton();
35
- this.jobs.push(jobInstance);
35
+ this.tasks.push(jobInstance);
36
36
  } catch (error) {
37
37
  new _app.ErrorHandler(`Falha ao iniciar um ou mais jobs: ${handlerFile}`, error);
38
38
  }
39
39
  }
40
40
  }
41
41
  async processAllJobs() {
42
- for (const job of this.jobs) {
43
- if (!job.getActive()) continue;
44
- job.taskInit();
45
- (0, _nodeSchedule.scheduleJob)(job.getCronTask(), job.execute.bind(job));
46
- this.log(`Job '${job.getName()}' started...`, 'warning');
42
+ for (const task of this.tasks) {
43
+ const intanceTask = new task();
44
+ if (!intanceTask.getActive()) continue;
45
+ intanceTask.taskInit();
46
+ (0, _nodeSchedule.scheduleJob)(intanceTask.getCronTask(), intanceTask.execute.bind(intanceTask));
47
+ this.log(`Job '${intanceTask.getName()}' started...`, 'warning');
47
48
  }
48
49
  }
49
50
  }
@@ -1,13 +1,41 @@
1
+ import { Worker } from 'cluster';
1
2
  import { Singleton } from '../../../app';
2
3
  import { eScheduleTaskInterval } from '../../../contracts/contansts';
4
+ export type TTaskWorkData = {
5
+ workId: string;
6
+ WorkData: any;
7
+ };
3
8
  declare abstract class ScheduleTask extends Singleton {
9
+ private eventCommunication;
10
+ protected workPerCluster: Map<string, number>;
11
+ protected lastDesignatedClusterId: number;
12
+ protected registeredClusters: Map<number, boolean>;
4
13
  execute(): Promise<void>;
5
14
  taskInit(): Promise<void>;
15
+ protected sendToTaskCluster(clusterId: number, event: string, data: any): void;
16
+ protected sendToTaskMaster(event: string, data: any): void;
6
17
  onTaskInit(): Promise<void> | void;
18
+ onTaskClusterInit(): Promise<void> | void;
19
+ onTaskMasterInit(): Promise<void> | void;
7
20
  getCronTask(): eScheduleTaskInterval | string;
8
21
  getActive(): boolean;
9
- abstract onExecute(): Promise<void> | void;
22
+ onExecute(): Promise<void> | void;
23
+ onClusterExecute(): Promise<void> | void;
24
+ onMasterExecute(): Promise<void> | void;
10
25
  abstract getName(): string;
26
+ addTaskWork(workId: string, workData: any): void;
27
+ protected sendTaskWorkToMaster(workId: string, workData: any): void;
28
+ protected taskClusterReceived(eventKey: string, data: any): void;
29
+ protected onTaskClusterReceivedData(_eventKey: string, _data: any): void;
30
+ protected onTaskClusterReceivedWork(_eventKey: string, _data: TTaskWorkData): void;
31
+ protected taskMasterReceived(worker: Worker, eventKey: string, data: any): void;
32
+ protected onTaskMasterReceived(worker: Worker, eventKey: string, data: any): void;
33
+ protected onTaskMasterReceivedWork(_worker: Worker, _eventKey: string, _data: TTaskWorkData): void;
34
+ protected onTaskMasterAcceptedWork(_worker: Worker, _eventKey: string, _data: TTaskWorkData): void;
35
+ protected sendTaskWorkToCluster(workId: string, workData: any): void;
36
+ protected onClusterExit(worker: Worker, code: number, signal: string): void;
37
+ protected taskClusterRegistered(_worker: Worker): void;
38
+ protected onTaskClusterRegistered(_worker: Worker): void;
11
39
  }
12
40
  export default ScheduleTask;
13
41
  //# sourceMappingURL=SchedulerTask.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SchedulerTask.d.ts","sourceRoot":"","sources":["../../../../src/services/task/scheduler/SchedulerTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,uBAAe,YAAa,SAAQ,SAAS;IAC9B,OAAO;IAGP,QAAQ;IAKd,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAGlC,WAAW,IAAI,qBAAqB,GAAG,MAAM;IAG7C,SAAS,IAAI,OAAO;aAIX,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;aACjC,OAAO,IAAI,MAAM;CAClC;AACD,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"SchedulerTask.d.ts","sourceRoot":"","sources":["../../../../src/services/task/scheduler/SchedulerTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAGrE,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,GAAG,CAAC;CACf,CAAC;AACF,uBAAe,YAAa,SAAQ,SAAS;IAC3C,OAAO,CAAC,kBAAkB,CAA2B;IACrD,SAAS,CAAC,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAa;IAC1D,SAAS,CAAC,uBAAuB,EAAE,MAAM,CAAK;IAC9C,SAAS,CAAC,kBAAkB,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAa;IAElD,OAAO;IAUP,QAAQ;IAsBrB,SAAS,CAAC,iBAAiB,CAAC,SAAS,EAAE,MAA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,SAAS,CAAC,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa;IAG3F,SAAS,CAAC,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG;IAU7D,SAAS,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAO3E,SAAS,CAAC,qBAAqB,CAAC,OAAO,EAAE,MAAM;IAQ/C,SAAS,CAAC,uBAAuB,CAAC,OAAO,EAAE,MAAM;CAGlD;AACD,eAAe,YAAY,CAAC"}
@@ -5,24 +5,161 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _app = require("../../../app");
8
+ var _service = require("../../../app/service");
8
9
  var _contansts = require("../../../contracts/contansts");
10
+ var _service2 = require("../../../contracts/service");
9
11
  class ScheduleTask extends _app.Singleton {
12
+ eventCommunication;
13
+ workPerCluster = new Map();
14
+ lastDesignatedClusterId = 0;
15
+ registeredClusters = new Map();
10
16
  async execute() {
11
17
  this.onExecute();
18
+ if (this.isCluster()) {
19
+ this.onClusterExecute();
20
+ }
21
+ if (this.isMaster()) {
22
+ this.onMasterExecute();
23
+ }
12
24
  }
13
25
  async taskInit() {
26
+ this.eventCommunication = new _service.EventCommunicationModule(this.constructor.name);
27
+ this.eventCommunication.on(_service2.eEventCommunication.RECEIVED_CLUSTER_MESSAGE, this.taskMasterReceived.bind(this));
28
+ this.eventCommunication.on(_service2.eEventCommunication.RECEIVED_MASTER_MESSAGE, this.taskClusterReceived.bind(this));
14
29
  this.onTaskInit();
30
+ if (this.isMaster()) {
31
+ this.onTaskMasterInit();
32
+ }
33
+ if (this.isCluster()) {
34
+ this.onTaskClusterInit();
35
+ this.sendToTaskMaster('task.init', {});
36
+ }
37
+ }
38
+ sendToTaskCluster(clusterId, event, data) {
39
+ this.eventCommunication.sendToServiceCluster(clusterId, event, data);
40
+ }
41
+ sendToTaskMaster(event, data) {
42
+ this.eventCommunication.sendToServiceMaster(event, data);
15
43
  }
16
44
 
17
45
  //# Muted methods
18
46
  onTaskInit() {
19
47
  return;
20
48
  }
49
+ onTaskClusterInit() {
50
+ return;
51
+ }
52
+ onTaskMasterInit() {
53
+ return;
54
+ }
21
55
  getCronTask() {
22
56
  return _contansts.eScheduleTaskInterval.DEFAULT;
23
57
  }
24
58
  getActive() {
25
59
  return true;
26
60
  }
61
+ onExecute() {
62
+ return;
63
+ }
64
+ onClusterExecute() {
65
+ return;
66
+ }
67
+ onMasterExecute() {
68
+ return;
69
+ }
70
+ addTaskWork(workId, workData) {
71
+ if (this.isCluster()) {
72
+ this.sendTaskWorkToMaster(workId, workData);
73
+ } else {
74
+ this.sendTaskWorkToCluster(workId, workData);
75
+ }
76
+ }
77
+
78
+ //# Cluster
79
+ sendTaskWorkToMaster(workId, workData) {
80
+ this.sendToTaskMaster('work.add', {
81
+ workId,
82
+ workData
83
+ });
84
+ }
85
+ taskClusterReceived(eventKey, data) {
86
+ switch (eventKey) {
87
+ case 'work.add':
88
+ this.onTaskClusterReceivedWork(eventKey, data);
89
+ break;
90
+ default:
91
+ this.onTaskClusterReceivedData(eventKey, data);
92
+ break;
93
+ }
94
+ }
95
+ onTaskClusterReceivedData(_eventKey, _data) {
96
+ return;
97
+ }
98
+ onTaskClusterReceivedWork(_eventKey, _data) {
99
+ return;
100
+ }
101
+
102
+ //# Master
103
+ taskMasterReceived(worker, eventKey, data) {
104
+ switch (eventKey) {
105
+ case 'work.add':
106
+ this.onTaskMasterReceivedWork(worker, eventKey, data);
107
+ break;
108
+ case 'work.add.accepted':
109
+ this.onTaskMasterAcceptedWork(worker, eventKey, data);
110
+ break;
111
+ case 'task.init':
112
+ this.taskClusterRegistered(worker);
113
+ break;
114
+ default:
115
+ this.onTaskMasterReceived(worker, eventKey, data);
116
+ break;
117
+ }
118
+ }
119
+ onTaskMasterReceived(worker, eventKey, data) {
120
+ switch (eventKey) {
121
+ case 'work.add':
122
+ this.onTaskMasterReceivedWork(worker, eventKey, data);
123
+ break;
124
+ case 'work.add.accepted':
125
+ this.onTaskMasterAcceptedWork(worker, eventKey, data);
126
+ break;
127
+ default:
128
+ console.log('mensagem desconhecida recebida', eventKey);
129
+ break;
130
+ }
131
+ }
132
+ onTaskMasterReceivedWork(_worker, _eventKey, _data) {
133
+ return;
134
+ }
135
+ onTaskMasterAcceptedWork(_worker, _eventKey, _data) {
136
+ return;
137
+ }
138
+ sendTaskWorkToCluster(workId, workData) {
139
+ const total = this.getClusterCount();
140
+ if (!this.workPerCluster.has(workId)) {
141
+ const nextCluster = this.lastDesignatedClusterId + 1 > total ? 1 : this.lastDesignatedClusterId + 1;
142
+ this.sendToTaskCluster(nextCluster, 'work.add', {
143
+ workId,
144
+ workData
145
+ });
146
+ }
147
+ }
148
+ onClusterExit(worker, code, signal) {
149
+ if (this.registeredClusters.has(worker.id)) {
150
+ console.log('removendo cluster da lista de registrados');
151
+ this.registeredClusters.delete(worker.id);
152
+ }
153
+ }
154
+ taskClusterRegistered(_worker) {
155
+ if (!this.registeredClusters.has(_worker.id)) {
156
+ console.log('registrando novo cluster', _worker.id);
157
+ this.registeredClusters.set(_worker.id, true);
158
+ }
159
+ this.onTaskClusterRegistered(_worker);
160
+ }
161
+ onTaskClusterRegistered(_worker) {
162
+ return;
163
+ }
27
164
  }
28
165
  var _default = exports.default = ScheduleTask;
@@ -0,0 +1,11 @@
1
+ import { Worker } from 'cluster';
2
+ import Service from '../app/service';
3
+ import { TClusterBroadCastMessage } from '../contracts/core';
4
+ declare class TestService extends Service {
5
+ protected onClusterInit(_worker: Worker): void;
6
+ protected onMasterInit(): void;
7
+ protected onMasterReceiveMessage(_worker: Worker, _message: TClusterBroadCastMessage): void;
8
+ protected onClusterReceiveMessage(_message: TClusterBroadCastMessage): void;
9
+ }
10
+ export default TestService;
11
+ //# sourceMappingURL=test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../src/services/test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,cAAM,WAAY,SAAQ,OAAO;IAC/B,SAAS,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAK9C,SAAS,CAAC,YAAY,IAAI,IAAI;IAI9B,SAAS,CAAC,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,wBAAwB,GAAG,IAAI;IAI3F,SAAS,CAAC,uBAAuB,CAAC,QAAQ,EAAE,wBAAwB,GAAG,IAAI;CAG5E;AAED,eAAe,WAAW,CAAC"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _service = _interopRequireDefault(require("../app/service"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ // import 'express-async-errors';
10
+
11
+ class TestService extends _service.default {
12
+ onClusterInit(_worker) {
13
+ console.log('iniciado no cluster');
14
+ this.sendMessageToMaster('evento.teste', 'olá');
15
+ }
16
+ onMasterInit() {
17
+ console.log('iniciado no master');
18
+ }
19
+ onMasterReceiveMessage(_worker, _message) {
20
+ console.log('mensagem recebida do cluster', _message);
21
+ this.sendToServiceCluster(_worker.id, 'evento.teste.resposta', 'olá amigo');
22
+ }
23
+ onClusterReceiveMessage(_message) {
24
+ console.log('mensagem recebida do master', _message);
25
+ }
26
+ }
27
+ var _default = exports.default = TestService;
@@ -0,0 +1,2 @@
1
+ export * from './queue';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tasks/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _queue = require("./queue");
7
+ Object.keys(_queue).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _queue[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _queue[key];
14
+ }
15
+ });
16
+ });
@@ -0,0 +1,2 @@
1
+ export { default as TestTaskQueue } from './teste';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tasks/queue/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "TestTaskQueue", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _teste.default;
10
+ }
11
+ });
12
+ var _teste = _interopRequireDefault(require("./teste"));
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -0,0 +1,9 @@
1
+ import { Job } from 'bullmq';
2
+ import { QueueTask } from '../../services';
3
+ declare class TestTaskQueue extends QueueTask<string> {
4
+ getName(): string;
5
+ onTaskInit(): Promise<void>;
6
+ onExecute(_job: Job<string, any, string>, _token?: string): Promise<any>;
7
+ }
8
+ export default TestTaskQueue;
9
+ //# sourceMappingURL=teste.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"teste.d.ts","sourceRoot":"","sources":["../../../src/tasks/queue/teste.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,cAAM,aAAc,SAAQ,SAAS,CAAC,MAAM,CAAC;IAC3C,OAAO,IAAI,MAAM;IAIX,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,SAAS,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;CAG/E;AAED,eAAe,aAAa,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _services = require("../../services");
8
+ class TestTaskQueue extends _services.QueueTask {
9
+ getName() {
10
+ return 'Teste Job Queue';
11
+ }
12
+ async onTaskInit() {
13
+ this.queue.drain();
14
+ }
15
+ async onExecute(_job, _token) {
16
+ this.log('this job queue handled');
17
+ }
18
+ }
19
+ var _default = exports.default = TestTaskQueue;
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tasks/schedule/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,21 @@
1
+ import { Worker } from 'cluster';
2
+ import { eScheduleTaskInterval } from '../../contracts/contansts';
3
+ import { ScheduleTask } from '../../services';
4
+ import { TTaskWorkData } from '../../services/task/scheduler/SchedulerTask';
5
+ declare class TestTaskSchedule extends ScheduleTask {
6
+ workPerCluster: Map<string, number>;
7
+ lastDesignatedClusterId: number;
8
+ getName(): string;
9
+ getCronTask(): eScheduleTaskInterval;
10
+ onClusterExecute(): Promise<void>;
11
+ onMasterExecute(): Promise<void>;
12
+ onTaskClusterInit(): Promise<void>;
13
+ addTaskWork(workId: string, workData: any): void;
14
+ protected onTaskClusterReceived(eventKey: string, data: any): void;
15
+ protected onTaskClusterReceivedWork(eventKey: string, data: TTaskWorkData): void;
16
+ protected onTaskMasterReceived(worker: Worker, eventKey: string, data: any): void;
17
+ protected onTaskMasterReceivedWork(worker: Worker, eventKey: string, data: TTaskWorkData): void;
18
+ protected onTaskMasterAcceptedWork(worker: Worker, eventKey: string, data: TTaskWorkData): void;
19
+ }
20
+ export default TestTaskSchedule;
21
+ //# sourceMappingURL=teste.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"teste.d.ts","sourceRoot":"","sources":["../../../src/tasks/schedule/teste.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAG5E,cAAM,gBAAiB,SAAQ,YAAY;IACzC,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAa;IAChD,uBAAuB,EAAE,MAAM,CAAK;IAE7B,OAAO,IAAI,MAAM;IAGjB,WAAW;IAGZ,gBAAgB;IAGhB,eAAe;IAIf,iBAAiB;IAMhB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG;IAShD,SAAS,CAAC,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG;IAG3D,SAAS,CAAC,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa;IAKzE,SAAS,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG;IAG1E,SAAS,CAAC,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa;IAGxF,SAAS,CAAC,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa;CAGzF;AAED,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _contansts = require("../../contracts/contansts");
8
+ var _services = require("../../services");
9
+ var _process = require("process");
10
+ class TestTaskSchedule extends _services.ScheduleTask {
11
+ workPerCluster = new Map();
12
+ lastDesignatedClusterId = 0;
13
+ getName() {
14
+ return 'Test Job Schedule';
15
+ }
16
+ getCronTask() {
17
+ return _contansts.eScheduleTaskInterval.DEFAULT;
18
+ }
19
+ async onClusterExecute() {
20
+ // this.log('this job handled');
21
+ }
22
+ async onMasterExecute() {
23
+ /* console.log('sending...');
24
+ this.sendTaskWorkToCluster('idworkd12344', 'testeeeeee'); */
25
+ }
26
+ async onTaskClusterInit() {
27
+ setTimeout(() => {
28
+ (0, _process.exit)();
29
+ }, 5000);
30
+ }
31
+ addTaskWork(workId, workData) {
32
+ if (this.isCluster()) {
33
+ this.sendTaskWorkToMaster(workId, workData);
34
+ } else {
35
+ this.sendTaskWorkToCluster(workId, workData);
36
+ }
37
+ }
38
+
39
+ //# Cluster
40
+ onTaskClusterReceived(eventKey, data) {
41
+ return;
42
+ }
43
+ onTaskClusterReceivedWork(eventKey, data) {
44
+ console.log('novo trabalho recebido neste cluster', data);
45
+ }
46
+
47
+ //# Master
48
+ onTaskMasterReceived(worker, eventKey, data) {
49
+ return;
50
+ }
51
+ onTaskMasterReceivedWork(worker, eventKey, data) {
52
+ // console.log('novo trabalho recebido no master');
53
+ }
54
+ onTaskMasterAcceptedWork(worker, eventKey, data) {
55
+ // console.log('o trabalho foi confirmado pelo cluster');
56
+ }
57
+ }
58
+ var _default = exports.default = TestTaskSchedule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exodus-framework",
3
- "version": "2.0.795",
3
+ "version": "2.0.797",
4
4
  "description": "Exodus Framework",
5
5
  "author": "jhownpaixao",
6
6
  "license": "ISC",