summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/index.ts15
-rw-r--r--src/tasks.ts4
2 files changed, 18 insertions, 1 deletions
diff --git a/src/index.ts b/src/index.ts
index 329d7b6..938b5f0 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,4 +1,4 @@
-import { addTask, getTask } from "./tasks";
+import { addTask, getTask, numOfTasksInQueue } from "./tasks";
import { runDownloadInstagramTask } from "./instagram_task";
import { runWithRetries, wait } from "./utils";
import { AppOptions, App as SlackApp } from "@slack/bolt";
@@ -6,6 +6,10 @@ import fs from "fs";
import dotenv from "dotenv";
dotenv.config();
+const QUEUE_MAX_LENGTH = process.env.QUEUE_MAX_LENGTH
+ ? Number(process.env.QUEUE_MAX_LENGTH)
+ : 3;
+
const slackAppConfig: AppOptions = {
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
@@ -19,6 +23,15 @@ const app = new SlackApp(slackAppConfig);
app.command("/veeti", async ({ command, ack, respond, client }) => {
await ack();
+
+ if (numOfTasksInQueue() >= QUEUE_MAX_LENGTH) {
+ void respond({
+ text: "Too many tasks in queue, please try again later.",
+ response_type: "ephemeral",
+ });
+ return;
+ }
+
console.log("Received command: /veeti", command.text);
const url = command.text.trim();
diff --git a/src/tasks.ts b/src/tasks.ts
index 18b6fe8..1b0ce9b 100644
--- a/src/tasks.ts
+++ b/src/tasks.ts
@@ -12,3 +12,7 @@ export const addTask = (task: Task) => {
export const getTask = (): Task | undefined => {
return taskQueue.shift();
};
+
+export const numOfTasksInQueue = () => {
+ return taskQueue.length;
+};