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

Commit

Permalink
chore: driveWorkerを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
yupix committed Sep 30, 2023
1 parent 558310f commit f7789aa
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"build-gulp": "gulp build",
"export": "pnpm build-ts && node ./built/migration/migrateAyuskeyNext.js",
"worker": "node ./built/migration/worker.js",
"drive-worker": "node ./built/migration/driveWorker.js",
"bnote-worker": "node ./built/migration/bNoteWorker.js",
"note-worker": "node ./built/migration/noteWorker.js",
"user-worker": "node ./built/migration/userAfterHookWorker.js",
Expand Down
43 changes: 43 additions & 0 deletions src/migration/driveWorker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { initDb } from "@/db/postgre";
import { logger } from "./common";
import { driveFileQueue } from "./jobqueue";
import driveFileProcessor from "./processor/driveFile.processor";
import { createConnection } from "typeorm";
import config from "@/config";
import { AyuskeyNextEntities } from "@/v13/models";

const cluster = require("cluster");

async function main() {
const numWorkers = 16;
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) => {
console.log(`worker ${worker.process.pid} died`);
});
} else {
driveFileQueue.process(driveFileProcessor);

driveFileQueue.on("completed", (job) => {
logger.succ(`DriveFile: ${job.data.driveFileId} の処理が完了しました`);
});
}
}

main().catch((e) => {
console.warn(e);
process.exit(1);
});

0 comments on commit f7789aa

Please sign in to comment.