-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (33 loc) · 1.18 KB
/
index.js
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
const { createClient } = require("@supabase/supabase-js");
const supabaseUrl = process.env.SUPABASE_URL;
const supabaseDevUrl = process.env.SUPABASE_DEV_URL;
const supabasePrivateKey = process.env.SUPABASE_KEY;
const supabaseDevPrivateKey = process.env.SUPABASE_DEV_KEY;
const supabase = createClient(supabaseUrl, supabasePrivateKey);
const supabaseDevClient = createClient(supabaseDevUrl, supabaseDevPrivateKey);
async function repeatEveryThreeSeconds() {
const { error, count } = await supabase
.from("queue")
.select("*", { count: "exact", head: true })
.eq("status", "queued");
console.log("🚀 ~ repeatEveryThreeSeconds ~ count:", count);
if (error) {
console.error(error);
}
if (count > 0) {
await fetch(process.env.QUEUE_URL);
}
// do the same thing for dev
const { error: devError, count: devCount } = await supabaseDevClient
.from("queue")
.select("*", { count: "exact", head: true })
.eq("status", "queued");
console.log("🚀 ~ repeatEveryThreeSeconds ~ devCount:", devCount);
if (devError) {
console.error(devError);
}
if (devCount > 0) {
await fetch(process.env.QUEUE_DEV_URL);
}
}
setInterval(repeatEveryThreeSeconds, 3000);