-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscheduler.js
More file actions
71 lines (61 loc) · 1.8 KB
/
scheduler.js
File metadata and controls
71 lines (61 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const cron = require("node-cron");
const { createBrowserClient } = require("@supabase/ssr");
const axios = require("axios");
const dotenv = require("dotenv");
// .env 파일 로드
dotenv.config({ path: ".env.local" });
const BASE_URL =
// process.env.NEXT_PUBLIC_API_BASE_URL || "http://localhost:3000";
process.env.NEXT_PUBLIC_API_BASE_URL;
// Supabase 클라이언트 생성
const supabase = createBrowserClient(
process.env.NEXT_PUBLIC_SUPABASE_URL,
process.env.NEXT_PUBLIC_SUPABASE_KEY
);
// scheduler for 10 minutes
// cron.schedule("*/10 * * * *", async () => {
cron.schedule("*/30 * * * * *", async () => {
console.log("Running STT and Topic scheduler");
sttScheduler();
topicScheduler();
});
async function sttScheduler() {
const { data, error } = await supabase
.from("Recording")
.select("id")
.eq("stt_status", "ready");
if (error) {
console.error("Error fetching recording:", error.message);
}
data.forEach(async (recording) => {
try {
const response = await axios.post(
`${BASE_URL}/api/recordings/${recording.id}/transcription`,
null
);
console.log("Transcription successfully requested");
} catch (error) {
console.error("Error while requesting transcription:", error);
}
});
}
async function topicScheduler() {
const { data, error } = await supabase
.from("Recording")
.select("id")
.eq("topic_status", "ready");
if (error) {
console.error("Error fetching recording:", error.message);
}
data.forEach(async (recording) => {
try {
const response = await axios.post(
`${BASE_URL}/api/recordings/${recording.id}/topic`,
null
);
console.log("Topic successfully requested");
} catch (error) {
console.error("Error while requesting topic:", error);
}
});
}