fix
This commit is contained in:
parent
07d5613aa1
commit
13c691a286
13
pkgs/prod.ts
13
pkgs/prod.ts
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
@ -58,4 +61,4 @@ const startMain = () => {
|
||||||
return worker;
|
return worker;
|
||||||
};
|
};
|
||||||
main.process = startMain();
|
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;
|
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;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue