diff options
author | Alan Pearce | 2024-04-16 00:46:38 +0200 |
---|---|---|
committer | Alan Pearce | 2024-04-16 00:46:38 +0200 |
commit | 2038e626ef78f466d1d138cc3b48b6e522f4b0ed (patch) | |
tree | f1b59b0356df5e8244d51f1ac05a9adf24d5e701 | |
parent | f97814c2cdc8d34d5816afe7ed81c841ead84998 (diff) | |
download | website-2038e626ef78f466d1d138cc3b48b6e522f4b0ed.tar.lz website-2038e626ef78f466d1d138cc3b48b6e522f4b0ed.tar.zst website-2038e626ef78f466d1d138cc3b48b6e522f4b0ed.zip |
disable auto-sleep (fly will charge for stopped machines soon)
-rw-r--r-- | fly.toml | 4 | ||||
-rw-r--r-- | src/app.ts | 12 | ||||
-rw-r--r-- | src/sleep.ts | 8 |
3 files changed, 2 insertions, 22 deletions
diff --git a/fly.toml b/fly.toml index d04e736..77017b1 100644 --- a/fly.toml +++ b/fly.toml @@ -15,9 +15,9 @@ primary_region = "ams" [http_service] internal_port = 3000 force_https = true - auto_stop_machines = true + auto_stop_machines = false auto_start_machines = true - min_machines_running = 1 + min_machines_running = 3 processes = ["app"] [http_service.http_options.response.headers] Strict-Transport-Security = "max-age=31536000; includeSubdomains; preload" diff --git a/src/app.ts b/src/app.ts index 6e714f9..a51e235 100644 --- a/src/app.ts +++ b/src/app.ts @@ -5,7 +5,6 @@ import type { BunFile, Serve } from "bun"; import * as Sentry from "@sentry/node"; import prom from "bun-prometheus-client"; import log from "loglevel"; -import { keepAwake } from "./sleep.ts"; import config from "./config"; @@ -26,10 +25,6 @@ const defaultHeaders = { vary: "Accept-Encoding", }; -const autoSleep = - import.meta.env.NODE_ENV === "production" && - import.meta.env["FLY_REGION"] !== import.meta.env["PRIMARY_REGION"]; - type File = { filename: string; handle: BunFile; @@ -270,15 +265,8 @@ export const server = { const seconds = endTimer(); metrics.requestDuration.observe(seconds); } - if (autoSleep && pathname !== "/health") { - keepAwake(); - } } }, } satisfies Serve; -if (autoSleep) { - keepAwake(); -} - export default server; diff --git a/src/sleep.ts b/src/sleep.ts deleted file mode 100644 index 663d472..0000000 --- a/src/sleep.ts +++ /dev/null @@ -1,8 +0,0 @@ -let sleepTimeout: Timer; - -export function keepAwake() { - if (sleepTimeout) clearTimeout(sleepTimeout); - sleepTimeout = setTimeout(function () { - process.exit(0); - }, 300_000); -} |