You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to implement Consumer for Step Functions in Node.js which will have n workers for activityArn. So far I have two classes written:
ActivityWorker - contains infinite loop with long-polling for tasks, which is breakable only if its status is not running anymore. Polling can be aborted by AWS AbortController if we need to stop worker emmidiately;
PoolManager - orchestrates lifecycles of workers: creates and starts them, stops them and replaces errored workers with fresh ones.
When I stop Manager, I stop and remove all workers that are managed by it. When I stop a worker I, among other things, abort the connection using AbortController. I can see that the connection is aborted and I don't see any new poll attempts. The problem is that if I create new execution of state machine after stopping a Manager I can see that so-called stopped worker started the execution. Could it be that AbortController does not abort the connection in some way?
...
asyncstop(): Promise<void>{this.#status =PoolManagerStatus.stoppingthis.#desiredCapacity =0letremainingAttempts=this.config.shutdown.maxAttemptswhile(this.#workers.size>0&&remainingAttempts>0){remainingAttempts-=1clearTimeout(this.#resizeTimeoutId)try{awaitthis.resizePool()console.log('workers after resizing',this.#workers)}catch(error){awaitsetTimeoutP(this.config.shutdown.intervalMs)}}this.#status =PoolManagerStatus.stopped}privateasyncresizePool(): Promise<void>{if(this.#resizeInProgress){thrownewResizeInProgressError()}this.#resizeInProgress =trueconstdesired=this.#desiredCapacity
awaitthis.cullWorkers()constpromises: Array<Promise<unknown>>=[]if(desired===this.#workers.size){return}elseif(this.#workers.size<desired){while(this.#workers.size<desired){constworker=this.generateWorker()this.#workers.set(worker.workerName,worker)promises.push(worker.start())}}elseif(this.#workers.size>desired){constworkerNames=Array.from(this.#workers.keys())while(this.#workers.size>desired){constname=workerNames.shift()if(!name){break}promises.push(this.removeWorker(name))}}try{awaitPromise.all(promises)}finally{this.#resizeInProgress =false}}privateasyncremoveWorker(name: string): Promise<void>{constworker=this.#workers.get(name)if(!worker){this.logger.warn({ name },'Worker with provided name does not exist')return}awaitworker.stop()this.#workers.delete(worker.workerName)}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi!
I am trying to implement Consumer for Step Functions in Node.js which will have n workers for activityArn. So far I have two classes written:
running
anymore. Polling can be aborted by AWSAbortController
if we need to stop worker emmidiately;When I stop Manager, I stop and remove all workers that are managed by it. When I stop a worker I, among other things, abort the connection using
AbortController
. I can see that the connection is aborted and I don't see any new poll attempts. The problem is that if I create new execution of state machine after stopping a Manager I can see that so-called stopped worker started the execution. Could it be thatAbortController
does not abort the connection in some way?Beta Was this translation helpful? Give feedback.
All reactions