This commit is contained in:
Rizky 2024-08-15 21:30:37 +07:00
parent 07d5613aa1
commit 13c691a286
2 changed files with 9 additions and 5 deletions

View File

@ -5,7 +5,8 @@ import { dir } from "utils/dir";
import { g } from "utils/global"; import { g } from "utils/global";
g.main = { g.main = {
process: null as null | Worker, old: null,
process: null,
restart: { restart: {
timeout: null as any, timeout: null as any,
}, },
@ -27,7 +28,7 @@ if (process.env.DATABASE_URL) {
try { try {
await Bun.write( await Bun.write(
dir("app/db/.env"), dir("app/db/.env"),
`DATABASE_URL=${process.env.DATABASE_URL}`, `DATABASE_URL=${process.env.DATABASE_URL}`
); );
await $({ cwd: dir(`app/db`) })`bun install`; await $({ cwd: dir(`app/db`) })`bun install`;
await $({ cwd: dir(`app/db`) })`bun prisma db pull --force`; await $({ cwd: dir(`app/db`) })`bun prisma db pull --force`;
@ -44,9 +45,11 @@ const startMain = () => {
const worker = new Worker("pkgs/index.ts"); const worker = new Worker("pkgs/index.ts");
worker.onmessage = (event) => { worker.onmessage = (event) => {
if (event.data === "restart") { if (event.data === "restart") {
const oldprocess = main.process; main.old = main.process;
setTimeout(() => { setTimeout(() => {
oldprocess?.postMessage("stop-server"); if (main.old) {
main.old.postMessage("stop-server");
}
}, 1000); }, 1000);
main.process = startMain(); main.process = startMain();
} }

View File

@ -48,6 +48,7 @@ export const g = global as unknown as {
firebaseInit: boolean; firebaseInit: boolean;
firebase: admin.app.App; firebase: admin.app.App;
main: { main: {
old: null | Worker;
process: null | Worker; process: null | Worker;
restart: { restart: {
timeout: any; timeout: any;