fix
This commit is contained in:
+8
-5
@@ -5,7 +5,8 @@ import { dir } from "utils/dir";
|
||||
import { g } from "utils/global";
|
||||
|
||||
g.main = {
|
||||
process: null as null | Worker,
|
||||
old: null,
|
||||
process: null,
|
||||
restart: {
|
||||
timeout: null as any,
|
||||
},
|
||||
@@ -27,7 +28,7 @@ if (process.env.DATABASE_URL) {
|
||||
try {
|
||||
await Bun.write(
|
||||
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 prisma db pull --force`;
|
||||
@@ -44,9 +45,11 @@ const startMain = () => {
|
||||
const worker = new Worker("pkgs/index.ts");
|
||||
worker.onmessage = (event) => {
|
||||
if (event.data === "restart") {
|
||||
const oldprocess = main.process;
|
||||
main.old = main.process;
|
||||
setTimeout(() => {
|
||||
oldprocess?.postMessage("stop-server");
|
||||
if (main.old) {
|
||||
main.old.postMessage("stop-server");
|
||||
}
|
||||
}, 1000);
|
||||
main.process = startMain();
|
||||
}
|
||||
@@ -58,4 +61,4 @@ const startMain = () => {
|
||||
return worker;
|
||||
};
|
||||
main.process = startMain();
|
||||
setTimeout(() => new Promise(() => 0), 0);
|
||||
setTimeout(() => new Promise(() => 0), 0);
|
||||
|
||||
@@ -48,6 +48,7 @@ export const g = global as unknown as {
|
||||
firebaseInit: boolean;
|
||||
firebase: admin.app.App;
|
||||
main: {
|
||||
old: null | Worker;
|
||||
process: null | Worker;
|
||||
restart: {
|
||||
timeout: any;
|
||||
|
||||
Reference in New Issue
Block a user