Skip to content

Worker

VonaJS uses a distributed architecture, allowing multiple worker processes to provide services simultaneously. It also supports single-process execution in a Docker environment

bean.worker

The module a-worker provides a global bean bean.worker for managing worker processes

  • Properties
NameDescription
idGets the current Worker ID
  • Methods
NameDescription
exitTerminates the current Worker
exitAllTerminates all Workers
reloadRestarts the current Worker
reloadAllRestarts all Workers
setAliveSets the alive status of a specified Worker
delAliveDeletes the alive status of a specified Worker
getAliveGets the alive status of a specified Worker

Examples

typescript
const workerId = this.bean.worker.id;
// reload current worker
this.bean.worker.reload();
// reload all workers
this.bean.worker.reloadAll();

SERVER_WORKERS

SERVER_WORKERS can be modified through the .env file

env/.env

typescript
# server
SERVER_WORKERS = 3

Alternatively, it can be set in the command line, for example:

package.json

bash
"scripts": {
  "dev": "npm run prerun && npm run vona :bin:dev -- --workers=2 --flavor=normal",
  "dev:one": "npm run prerun && npm run vona :bin:dev -- --workers=1 --flavor=normal",
  "start": "node ./dist/normal/bootstrap.js",
  "start:one": "cross-env SERVER_WORKERS=1 node ./dist/normal/bootstrap.js",
  "start:docker": "cross-env SERVER_WORKERS=1 node ./dist/docker/bootstrap.js",
}
  • When executing npm run dev, two workers will be started. This allows for timely troubleshooting of potential issues in a distributed environment during development

Released under the MIT License.