feat: allow horizontal scaling

This commit is contained in:
April John 2023-05-17 00:08:14 +02:00
parent 3897adaed7
commit 6a5b9009f0
4 changed files with 11 additions and 3 deletions

View File

@ -124,6 +124,9 @@ reservedUsernames: [
# Number of worker processes # Number of worker processes
#clusterLimit: 1 #clusterLimit: 1
# Worker only mode
#onlyQueueProcessor: 1
# Job concurrency per worker # Job concurrency per worker
# deliverJobConcurrency: 128 # deliverJobConcurrency: 128
# inboxJobConcurrency: 16 # inboxJobConcurrency: 16

View File

@ -93,7 +93,7 @@ export async function masterMain() {
true, true,
); );
if (!envOption.noDaemons) { if (!envOption.noDaemons && !config.onlyQueueProcessor) {
import("../daemons/server-stats.js").then((x) => x.default()); import("../daemons/server-stats.js").then((x) => x.default());
import("../daemons/queue-stats.js").then((x) => x.default()); import("../daemons/queue-stats.js").then((x) => x.default());
import("../daemons/janitor.js").then((x) => x.default()); import("../daemons/janitor.js").then((x) => x.default());

View File

@ -1,5 +1,6 @@
import cluster from "node:cluster"; import cluster from "node:cluster";
import { initDb } from "../db/postgre.js"; import { initDb } from "../db/postgre.js";
import config from "@/config/index.js";
/** /**
* Init worker process * Init worker process
@ -7,8 +8,10 @@ import { initDb } from "../db/postgre.js";
export async function workerMain() { export async function workerMain() {
await initDb(); await initDb();
// start server if (!config.onlyQueueProcessor) {
await import("../server/index.js").then((x) => x.default()); // start server
await import("../server/index.js").then((x) => x.default());
}
// start job queue // start job queue
import("../queue/index.js").then((x) => x.default()); import("../queue/index.js").then((x) => x.default());

View File

@ -52,6 +52,8 @@ export type Source = {
clusterLimit?: number; clusterLimit?: number;
onlyQueueProcessor?: boolean;
id: string; id: string;
outgoingAddressFamily?: "ipv4" | "ipv6" | "dual"; outgoingAddressFamily?: "ipv4" | "ipv6" | "dual";