Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
chore: test
Browse files Browse the repository at this point in the history
  • Loading branch information
yupix committed Sep 30, 2023
1 parent 1be5453 commit 4dde26e
Showing 1 changed file with 24 additions and 31 deletions.
55 changes: 24 additions & 31 deletions src/migration/noteWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,30 @@ import config from "@/config";
import { AyuskeyNextEntities } from "@/v13/models";
import cluster from "cluster";

async function main() {
const numWorkers = 8;
const numWorkers = 8;

if (cluster.isPrimary) {
for (let i = 0; i < numWorkers; i++) {
cluster.fork();
}
cluster.on("exit", (worker, code, signal) => {
console.log(`worker ${worker.process.pid} died`);
});
} else {
await initDb();
await createConnection({
name: "nextDb",
type: "postgres",
host: config.db.nextDb.host,
port: config.db.nextDb.port,
username: config.db.nextDb.user,
password: config.db.nextDb.pass,
database: config.db.nextDb.db,
entities: AyuskeyNextEntities,
});

noteQueue.process(noteProcessor);
noteQueue.on("completed", (job) => {
logger.succ(`Note: ${job.data.id} の処理が完了しました`);
});
if (cluster.isPrimary) {
for (let i = 0; i < numWorkers; i++) {
cluster.fork();
}
}
cluster.on("exit", (worker, code, signal) => {
console.log(`worker ${worker.process.pid} died`);
});
} else {
initDb();
createConnection({
name: "nextDb",
type: "postgres",
host: config.db.nextDb.host,
port: config.db.nextDb.port,
username: config.db.nextDb.user,
password: config.db.nextDb.pass,
database: config.db.nextDb.db,
entities: AyuskeyNextEntities,
});

main().catch((e) => {
console.warn(e);
process.exit(1);
});
noteQueue.process(noteProcessor);
noteQueue.on("completed", (job) => {
logger.succ(`Note: ${job.data.id} の処理が完了しました`);
});
}

0 comments on commit 4dde26e

Please sign in to comment.