From 25635ddb385a5c17d63b5ca8e70f6d1dc63f89cf Mon Sep 17 00:00:00 2001 From: Zhijie He Date: Fri, 5 Jun 2026 02:07:03 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(task):=20auto-ensure=20qstash?= =?UTF-8?q?=20schedule=20for=20task=20system=20(#14771)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ✨ feat(task): auto-ensure qstash schedule chore: cleanup code chore: cleanup code chore: cleanup code * chore: migrate qstash init workflow to startServer chore: migrate qstash init workflow to startServer * fix: set default QSTASH_URL to eu region, same as SDK fix: set default QSTASH_URL to eu region, same as SDK --- scripts/serverLauncher/startServer.js | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/scripts/serverLauncher/startServer.js b/scripts/serverLauncher/startServer.js index a360445111..dd80221978 100644 --- a/scripts/serverLauncher/startServer.js +++ b/scripts/serverLauncher/startServer.js @@ -163,6 +163,47 @@ const startGateway = async () => { console.error('❌ Gateway: Failed to start after retries.'); }; +// Function to create QStash schedule for dispatching workflow tasks every 10 minutes +const createQstashSchedule = async () => { + const QSTASH_URL = process.env.QSTASH_URL || 'https://qstash-eu-central-1.upstash.io'; + + const QSTASH_TOKEN = process.env.QSTASH_TOKEN; + if (!QSTASH_TOKEN) { + console.warn('⚠️ QStash: QSTASH_TOKEN not set. Skipping schedule creation.'); + return; + } + + const APP_URL = process.env.APP_URL; + if (!APP_URL) { + console.warn('⚠️ QStash: APP_URL not set. Skipping schedule creation.'); + return; + } + + const url = `${QSTASH_URL}/v2/schedules/${APP_URL}/api/workflows/task/schedule-dispatch`; + + try { + const res = await fetch(url, { + method: 'POST', + headers: { + 'Authorization': `Bearer ${QSTASH_TOKEN}`, + 'Content-Type': 'application/json', + 'Upstash-Method': 'POST', + 'Upstash-Cron': '*/10 * * * *', + 'Upstash-Schedule-Id': 'lobe-task-schedule-dispatch', + }, + body: JSON.stringify({}), + }); + + if (res.ok) { + console.log('✅ QStash: Schedule created successfully.'); + } else { + console.error(`❌ QStash: Failed to create schedule. Status ${res.status}`); + } + } catch (err) { + console.error('❌ QStash: Error creating schedule:', err); + } +}; + // Main function to run the server with optional proxy const runServer = async () => { const PROXY_URL = process.env.PROXY_URL || ''; // Default empty string to avoid undefined errors @@ -204,6 +245,9 @@ const runServer = async () => { // Start gateway in background after server is ready startGateway(); + // Create QStash schedule for workflow task dispatching + createQstashSchedule(); + // Run the server in either database or non-database mode await runServer(); })();