diff --git a/package.json b/package.json index 8e15f02ee..38494eddc 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/migration/driveWorker.ts b/src/migration/driveWorker.ts new file mode 100644 index 000000000..0e183270a --- /dev/null +++ b/src/migration/driveWorker.ts @@ -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); +});