From 1eb48c4299343cb000b1c161317b22e71cacd36a Mon Sep 17 00:00:00 2001 From: Lanskikh Date: Tue, 3 Jun 2025 14:19:34 +0500 Subject: [PATCH] upd --- .env | 2 +- src/db/schema/servers.ts | 3 +++ src/index.ts | 14 +++++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.env b/.env index 3c9117c..8fa6512 100644 --- a/.env +++ b/.env @@ -2,4 +2,4 @@ PORT=3001 DB_URL=postgres://postgres:v1sq3vD5faXL@194.26.138.94:5432/mate HMAC_SECRET=9a9ccda5db157ccfd04b4094264c55f58097f85d1fd6c22fbab0a86680dd3efd API_URL=http://localhost:3000 -COMPANY_ID=56e69b37-15e6-4de4-b953-e77435a09a06 \ No newline at end of file +COMPANY_ID=2a4f54db-7a1f-42c2-a965-3b185d92b063 diff --git a/src/db/schema/servers.ts b/src/db/schema/servers.ts index c314297..0e776ed 100644 --- a/src/db/schema/servers.ts +++ b/src/db/schema/servers.ts @@ -19,6 +19,9 @@ export const serversTable = pgTable("servers", { .notNull() .defaultNow() .$onUpdate(() => new Date()), + status: varchar("status", { enum: ["online", "offline"] }) + .notNull() + .default("online"), }); export const serversRelations = relations(serversTable, ({ one, many }) => ({ diff --git a/src/index.ts b/src/index.ts index 9354d86..80ce888 100644 --- a/src/index.ts +++ b/src/index.ts @@ -218,7 +218,19 @@ if (!serverInfo) { process.exit(1); } -cron.schedule("* * * * * *", scheduleSession); +async function updateStatus() { + try { + await db + .update(serversTable) + .set({ status: "online" }) + .where(eq(serversTable.id, serverInfo!.id)); + } catch (error) { + console.log("Error updating status", error); + } +} + +cron.schedule("*/5 * * * * *", scheduleSession); +cron.schedule("*/10 * * * * *", updateStatus); serve({ port: 3001,