Crash fixes
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { RequestId } from "common";
|
||||
import { Effect, Exit, Layer, Option as O, pipe, Scope, unsafeCoerce } from "effect";
|
||||
import { Effect, Exit, Layer, ManagedRuntime, Option as O, pipe, Scope, unsafeCoerce } from "effect";
|
||||
import { ulid } from "ulid";
|
||||
import { app } from "./app";
|
||||
import { DatabaseLive } from "./services/database";
|
||||
@@ -8,16 +8,11 @@ import { StorageFilesystem } from "./services/storage";
|
||||
|
||||
const scope = Effect.runSync(Scope.make());
|
||||
|
||||
const layers = pipe(
|
||||
Layer.merge(
|
||||
StorageFilesystem("storage"),
|
||||
pipe(
|
||||
DatabaseLive(),
|
||||
Layer.provide(Layer.succeed(Scope.Scope, scope)),
|
||||
),
|
||||
),
|
||||
Layer.memoize,
|
||||
Effect.provideService(Scope.Scope, scope),
|
||||
const runtime = pipe(
|
||||
StorageFilesystem("storage"),
|
||||
Layer.merge(DatabaseLive()),
|
||||
Layer.provide(Layer.succeed(Scope.Scope, scope)),
|
||||
ManagedRuntime.make,
|
||||
);
|
||||
|
||||
const server = Bun.serve({
|
||||
@@ -50,10 +45,9 @@ const server = Bun.serve({
|
||||
});
|
||||
|
||||
const fiber = pipe(
|
||||
layers,
|
||||
Effect.flatMap((layers) => Effect.provide(app, layers)),
|
||||
app,
|
||||
Effect.provideService(Request, requestInterface),
|
||||
Effect.runFork,
|
||||
runtime.runFork,
|
||||
);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -69,6 +63,9 @@ const server = Bun.serve({
|
||||
});
|
||||
|
||||
process.on("SIGINT", () => {
|
||||
Effect.withFiberRuntime((fiber) => Scope.close(scope, Exit.interrupt(fiber.id())));
|
||||
Effect.runFork(Effect.gen(function* () {
|
||||
yield* runtime.disposeEffect;
|
||||
yield* Scope.close(scope, Exit.void);
|
||||
}));
|
||||
server.stop();
|
||||
});
|
||||
|
||||
@@ -62,7 +62,7 @@ export const DatabaseLive = (filePath: string = "db.sqlite3") => Layer.effect(Da
|
||||
db.exec(`CREATE TABLE IF NOT EXISTS Session (
|
||||
sessionId TEXT NOT NULL PRIMARY KEY,
|
||||
userId TEXT NOT NULL REFERENCES User (userId) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
expiresAt TEXT NOT NULL,
|
||||
expiresAt TEXT NOT NULL
|
||||
)`);
|
||||
|
||||
db.exec(`CREATE TABLE IF NOT EXISTS Attachment (
|
||||
|
||||
Reference in New Issue
Block a user