-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from SFU-Blueprint/feature/continuous-update
feat/created a cronjob to get the data from keep_db_active table ever…
- Loading branch information
Showing
5 changed files
with
155 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// src/app/api/keep-db-active/route.ts | ||
/* eslint-disable import/prefer-default-export */ | ||
import { NextResponse } from "next/server"; | ||
import supabase from "@/lib/supabase"; | ||
|
||
export async function GET() { | ||
const { data, error } = await supabase.from("keep_db_active").select("*"); | ||
|
||
if (error) { | ||
return NextResponse.json({ error: "Error fetching data" }, { status: 500 }); | ||
} | ||
|
||
return NextResponse.json(data, { status: 200 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// cronJob.mjs | ||
import cron from "node-cron"; | ||
import fetch from "node-fetch"; | ||
|
||
const fetchData = async () => { | ||
try { | ||
const res = await fetch("http://localhost:3000/api/keep-db-active"); | ||
const data = await res.json(); | ||
console.log("Fetched data:", data); | ||
} catch (error) { | ||
console.error("Error fetching data:", error); | ||
} | ||
}; | ||
|
||
// Schedule the task to run every day at midnight | ||
cron.schedule("* * * * * *", fetchData); | ||
|
||
console.log("Cron job started: Fetching data every second"); | ||
|
||
export default function startCronJob() { | ||
cron.schedule("* * * * * *", fetchData); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
import startCronJob from "../src/cronJob.mjs"; | ||
|
||
/** @type {import('next').NextConfig} */ | ||
export default {}; | ||
const nextConfig = { | ||
webpack: (config, { isServer }) => { | ||
if (isServer) { | ||
startCronJob(); | ||
} | ||
return config; | ||
} | ||
}; | ||
|
||
export default nextConfig; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters