blob: f184d1316645db3d104618a49d14b485dd7b52e7 (
plain)
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
|
import { addTask, getTask } from "./tasks";
import { runDownloadInstagramTask } from "./instagram_task";
import { runWithRetries, wait } from "./utils";
// TESTING DATA
addTask({
type: "download_instagram",
url: "https://www.instagram.com/reel/C33u39RBF5p/?igsh=MXZuZ2drN2wya2JmZg==",
replyId: "123",
});
(async () => {
const MAX_RETRIES = 5;
// Main loop
while (true) {
const task = getTask();
if (task) {
try {
await runWithRetries(async () => {
if (task.type === "download_instagram") {
await runDownloadInstagramTask(task);
} else if (task.type === "slack_reply") {
console.log("TODO slack reply task");
} else {
console.log("Unknown task type, skipping", task);
}
}, MAX_RETRIES);
} catch (e) {
console.error("Task failed after max retries, skipping task.", task, e);
}
} else {
await wait(1000);
}
}
})();
|