diff --git a/.github/workflows/supabase-activity.yml b/.github/workflows/activity.yml similarity index 62% rename from .github/workflows/supabase-activity.yml rename to .github/workflows/activity.yml index 11fdfe0..9e091fb 100644 --- a/.github/workflows/supabase-activity.yml +++ b/.github/workflows/activity.yml @@ -1,7 +1,7 @@ name: Supabase Activity on: schedule: - - cron: "0 0 * * 0,3" + - cron: "0 9 * * 1,4" workflow_dispatch: jobs: @@ -9,4 +9,4 @@ jobs: runs-on: ubuntu-latest steps: - name: Send HTTP Request - run: curl https://trophy-hunt.vercel.app/api/supabase-activity + run: curl https://trophy-hunt.vercel.app/api/activity diff --git a/app/api/activity/route.ts b/app/api/activity/route.ts new file mode 100644 index 0000000..6982bbc --- /dev/null +++ b/app/api/activity/route.ts @@ -0,0 +1,24 @@ +import { createClient } from "@/utils/supabase/server"; +import { cookies } from "next/headers"; + +interface Data { + id: number; + value: string; +} + +const table = "keep-alive"; + +export const GET = async (): Promise => { + try { + const sb = createClient(cookies()); + const { data, error } = await sb.from(table).select("id").single(); + if (error !== null) throw new Error(error.message); + const payload = { value: new Date().toISOString() }; + const remove = await sb.from(table).update(payload).eq("id", data.id); + if (remove.error !== null) throw new Error(remove.error.message); + return Response.json(`Success! ${payload.value}`); + } catch (error) { + const message = (error as Error).message ?? "An error occurred."; + return Response.json(message, { status: 400 }); + } +}; diff --git a/app/api/supabase-activity/route.ts b/app/api/supabase-activity/route.ts deleted file mode 100644 index d86b835..0000000 --- a/app/api/supabase-activity/route.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { createClient } from "@/utils/supabase/server"; -import { cookies } from "next/headers"; - -export const GET = async (): Promise => { - try { - const supabase = createClient(cookies()); - const { data, error } = await supabase - .from("games") - .select("created_at") - .limit(1); - if (error !== null) throw new Error(error.message); - return Response.json(data); - } catch (error) { - const message = (error as Error).message ?? "An error occurred."; - return Response.json({ error: message }, { status: 400 }); - } -};