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

Commit

Permalink
chore: 高速化
Browse files Browse the repository at this point in the history
  • Loading branch information
yupix committed Sep 30, 2023
1 parent 6dbd1e1 commit 46770f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
27 changes: 19 additions & 8 deletions src/migration/bNoteWorker.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
import { initDb } from "@/db/postgre";
import { logger } from "./common";
import { noteQueue } from "./jobqueue";
import { createConnection } from "typeorm";
import config from "@/config";
import { AyuskeyNextEntities } from "@/v13/models";
import noteProcessor from "./processor/note.processor";


const cluster = require('cluster');
const cluster = require("cluster");

async function main() {
const numWorkers = 128;

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,
});
if (cluster.isPrimary) {
for (let i = 0; i < numWorkers; i++) {
cluster.fork();
}
cluster.on("exit", (worker: any, code :any, signal:any) => {
cluster.on("exit", (worker: any, code: any, signal: any) => {
console.log(`worker ${worker.process.pid} died`);
});
} else {


noteQueue.process(__dirname + "/processor/note.processor.js");
noteQueue.process(noteProcessor);
noteQueue.on("completed", (job) => {
logger.succ(`Note: ${job.data.note.id} の処理が完了しました`);
});
}
}


main().catch((e) => {
console.warn(e);
process.exit(1);
Expand Down
17 changes: 1 addition & 16 deletions src/migration/processor/note.processor.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
import { Job } from "bull";
import { migrateNote } from "../note";
import { Note } from "@/models/entities/note";
import { initDb } from "@/db/postgre";
import { createConnection } from "typeorm";
import config from "@/config";
import { AyuskeyNextEntities } from "@/v13/models";

export default async (job: Job<{noteId: string, note: Note}>, done: any) => {
await initDb();
const con = 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,
});

job.progress(job.data.noteId);
await migrateNote(job.data.noteId, job.data.note);
done();
await con.close();

}

0 comments on commit 46770f3

Please sign in to comment.