- public execute (data: Data): Promise<Response> {
- // Configure worker to handle message with the specified task
- const worker = this.chooseWorker()
- const res = this.internalExecute(worker, this.nextMessageId)
- this.checkAndEmitBusy()
- this.sendToWorker(worker, {
+ public setTasksQueueOptions (opts: TasksQueueOptions): void {
+ if (this.opts.enableTasksQueue === true) {
+ this.checkValidTasksQueueOptions(opts)
+ this.opts.tasksQueueOptions = this.buildTasksQueueOptions(opts)
+ } else {
+ delete this.opts.tasksQueueOptions
+ }
+ }
+
+ private buildTasksQueueOptions (
+ tasksQueueOptions: TasksQueueOptions
+ ): TasksQueueOptions {
+ return {
+ concurrency: tasksQueueOptions?.concurrency ?? 1
+ }
+ }
+
+ /**
+ * Whether the pool is full or not.
+ *
+ * The pool filling boolean status.
+ */
+ protected abstract get full (): boolean
+
+ /**
+ * Whether the pool is busy or not.
+ *
+ * The pool busyness boolean status.
+ */
+ protected abstract get busy (): boolean
+
+ protected internalBusy (): boolean {
+ return this.findFreeWorkerNodeKey() === -1
+ }
+
+ /** @inheritDoc */
+ public findFreeWorkerNodeKey (): number {
+ return this.workerNodes.findIndex(workerNode => {
+ return workerNode.tasksUsage?.running === 0
+ })
+ }
+
+ /** @inheritDoc */
+ public async execute (data: Data): Promise<Response> {
+ const [workerNodeKey, workerNode] = this.chooseWorkerNode()
+ const submittedTask: Task<Data> = {
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions