From c890ea83d6e49702f0e3201b29c472f095193133 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Wed, 13 Mar 2024 21:21:05 +0200 Subject: Initial commit --- src/index.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/index.ts (limited to 'src/index.ts') diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..f184d13 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,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); + } + } +})(); -- cgit v1.3