all repos — homestead @ 798e6679d780e1b53153ce8141edc44ac8a99292

Code for my website

disable auto-sleep (fly will charge for stopped machines soon)

Alan Pearce
commit

798e6679d780e1b53153ce8141edc44ac8a99292

parent

97b600d40737f80f76c103dfbe083fbfe299b5d7

3 files changed, 2 insertions(+), 22 deletions(-)

jump to
M fly.tomlfly.toml
@@ -15,9 +15,9 @@
[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"
M src/app.tssrc/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";
@@ -25,10 +24,6 @@ const defaultHeaders = {
...config.extra.headers, 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;
@@ -270,15 +265,8 @@ if (status === 200) {
const seconds = endTimer(); metrics.requestDuration.observe(seconds); } - if (autoSleep && pathname !== "/health") { - keepAwake(); - } } }, } satisfies Serve; - -if (autoSleep) { - keepAwake(); -} export default server;
D src/sleep.ts
@@ -1,8 +0,0 @@
-let sleepTimeout: Timer; - -export function keepAwake() { - if (sleepTimeout) clearTimeout(sleepTimeout); - sleepTimeout = setTimeout(function () { - process.exit(0); - }, 300_000); -}