Run scheduled tasks through application database
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
const endpoint = process.env.SCHEDULER_URL;
|
||||
const token = process.env.SCHEDULER_TOKEN;
|
||||
if (!endpoint || !token) throw new Error('SCHEDULER_URL and SCHEDULER_TOKEN are required.');
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
const response = await fetch(endpoint, {
|
||||
method: 'POST',
|
||||
headers: { authorization: `Bearer ${token}` }
|
||||
});
|
||||
if (!response.ok) throw new Error(`Scheduler endpoint returned HTTP ${response.status}.`);
|
||||
console.log(`Scheduler tick: ${JSON.stringify(await response.json())}`);
|
||||
} catch (error) {
|
||||
console.error('Scheduler tick failed', error);
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 60_000));
|
||||
}
|
||||
Reference in New Issue
Block a user