diff --git a/.dockerignore b/.dockerignore index 2e390aa99d..4f1d395d29 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,4 +4,5 @@ **/README.md **/.next **/.git -node_modules \ No newline at end of file +node_modules +openstatus.db \ No newline at end of file diff --git a/apps/server/fly.toml b/apps/server/fly.toml index 3e54ecda6c..084e461d09 100644 --- a/apps/server/fly.toml +++ b/apps/server/fly.toml @@ -14,8 +14,8 @@ primary_region = "ams" internal_port = 3000 force_https = true auto_stop_machines = false - auto_start_machines = true - min_machines_running = 2 + auto_start_machines = false + min_machines_running = 12 processes = ["app"] [http_service.concurrency] type = "requests" diff --git a/apps/server/src/checker/checker.test.ts b/apps/server/src/checker/checker.test.ts index 0c79296a3c..a8cf93e97a 100644 --- a/apps/server/src/checker/checker.test.ts +++ b/apps/server/src/checker/checker.test.ts @@ -11,11 +11,13 @@ mock.module("./ping.ts", () => { test("should call upsertMonitorStatus when we can fetch", async () => { const fn = mock(() => {}); - mock.module("./alerting.ts", () => { + mock.module("./monitor-handler.ts", () => { return { - upsertMonitorStatus: fn, + handleMonitorFailed: mock(() => {}), + handleMonitorRecovered: fn, }; }); + await checkerRetryPolicy({ workspaceId: "1", monitorId: "1", @@ -31,9 +33,10 @@ test("should call upsertMonitorStatus when we can fetch", async () => { test("should call upsertMonitorStatus when status error", async () => { const fn = mock(() => {}); - mock.module("./alerting.ts", () => { + mock.module("./monitor-handler.ts", () => { return { - upsertMonitorStatus: fn, + handleMonitorFailed: fn, + handleMonitorRecovered: mock(() => {}), }; }); try { @@ -55,9 +58,9 @@ test("should call upsertMonitorStatus when status error", async () => { test("What should we do when redirect ", async () => { const fn = mock(() => {}); - mock.module("./alerting.ts", () => { + mock.module("./monitor-handler.ts", () => { return { - upsertMonitorStatus: fn, + handleMonitorFailed: fn, }; }); try { @@ -79,17 +82,15 @@ test("What should we do when redirect ", async () => { test("When 404 we should trigger alerting ", async () => { const fn = mock(() => {}); const fn1 = mock(() => {}); - const fn2 = mock(() => {}); - mock.module("./alerting.ts", () => { + mock.module("./ping.ts", () => { return { - upsertMonitorStatus: fn, - triggerAlerting: fn1, + publishPing: fn, }; }); - mock.module("./ping.ts", () => { + mock.module("./monitor-handler.ts", () => { return { - publishPing: fn2, + handleMonitorFailed: fn1, }; }); try { @@ -107,24 +108,20 @@ test("When 404 we should trigger alerting ", async () => { } expect(fn).toHaveBeenCalledTimes(1); expect(fn1).toHaveBeenCalledTimes(1); - expect(fn2).toHaveBeenCalledTimes(1); }); test("When error 404 we should not trigger alerting ", async () => { const fn = mock(() => {}); const fn1 = mock(() => {}); - const fn2 = mock(() => {}); - mock.module("./alerting.ts", () => { + mock.module("./ping.ts", () => { return { - upsertMonitorStatus: fn, - triggerAlerting: fn1, + publishPing: fn, }; }); - - mock.module("./ping.ts", () => { + mock.module("./monitor-handler.ts", () => { return { - publishPing: fn2, + handleMonitorFailed: fn1, }; }); try { @@ -140,7 +137,6 @@ test("When error 404 we should not trigger alerting ", async () => { } catch (e) { expect(e).toBeInstanceOf(Error); } - expect(fn).toHaveBeenCalledTimes(0); + expect(fn).toHaveBeenCalledTimes(1); expect(fn1).toHaveBeenCalledTimes(0); - expect(fn2).toHaveBeenCalledTimes(1); }); diff --git a/apps/server/src/checker/checker.ts b/apps/server/src/checker/checker.ts index 92e6237222..9cc40df12d 100644 --- a/apps/server/src/checker/checker.ts +++ b/apps/server/src/checker/checker.ts @@ -75,7 +75,7 @@ const run = async (data: Payload, retry: number) => { message: undefined, }); if (data?.status === "error") { - handleMonitorRecovered(data, res); + await handleMonitorRecovered(data, res); } } else { if (retry < 2) { @@ -94,8 +94,8 @@ const run = async (data: Payload, retry: number) => { statusCode: res?.status, message, }); - if (data?.status === "active") { - handleMonitorFailed(data, res, message); + if (data.status === "active") { + await handleMonitorFailed(data, res, message); } } }