-
Notifications
You must be signed in to change notification settings - Fork 66
Description
Bug Report
Current Behavior
I am able to add both cron jobs and enqueue other task. However when they are processed nothing is logged to the console and no external domains are contacted.
I am using SvleteKit btw
Input Code
- REPL or Repo link if applicable:
import { Queue } from "quirrel/sveltekit";
export const alertsQueue = Queue(
"/alerts-queue", // 👈 the route it's reachable on
async (name) => {
console.log(`Greetings, ${name}!`);
try {
const response = await fetch('https://rb.gy/y8avpb', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
if (!response.ok) {
// Handle errors here (e.g., throw an error or log the issue)
throw new Error(`Error posting data: ${response.statusText}`);
}
console.log('Data posted successfully!');
} catch (error) {
console.error('Error posting data:', error);
}
});
export const enqueueAlert = async (request) => {
const url = new URL(request.url);
const searchParams = url.searchParams;
const name = searchParams.get('name');
console.log(`Enqueuing alert for ${name}`);
await alertsQueue.enqueue(name, {
delay: "3s",
});
return "ok";
}
export const cronHandler = async () => {
console.log('Running cron job');
let data = { name: "John Doe" };
try {
const response = await fetch('https://rb.gy/y8avpb', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
if (!response.ok) {
// Handle errors here (e.g., throw an error or log the issue)
throw new Error(`Error posting data: ${response.statusText}`);
}
console.log('Data posted successfully!');
} catch (error) {
console.error('Error posting data:', error);
}
};
export default alertsQueue;
The above exports are imported to the +server.js file here:
import { CronJob } from "quirrel/next";
import { alertsQueue, enqueueAlert, cronHandler } from "./queues.js";
const alertCron = CronJob(
"/alerts-queue", // the route that it's reachable on
["* * * * *", "America/Chicago"], // every day at 2AM, in Berlin time. you can also write @weekly or @daily!
cronHandler
);
export const POST = alertsQueue;
export const GET = async (request) => {
// Call the appropriate function based on the request
const result = await enqueueAlert(request);
return new Response(result, { status: 200 })
}
Expected behavior/code
I would expect that the handler would be executed on schedule, the data logged out to the console, and the external link fetched.
Environment
{
"name": "prg",
"version": "0.0.1",
"scripts": {
"dev": "concurrently 'vite dev' 'quirrel'",
"build": "vite build",
"preview": "vite preview",
"lint": "eslint ."
},
"devDependencies": {
"@fontsource/fira-mono": "^4.5.10",
"@neoconfetti/svelte": "^1.0.0",
"@prisma/client": "^4.11.0",
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@types/eslint": "8.56.0",
"eslint": "^8.56.0",
"eslint-plugin-svelte": "^2.35.1",
"prisma": "^4.11.0",
"svelte": "^4.2.7",
"vite": "^5.0.3"
},
"type": "module",
"dependencies": {
"quirrel": "^1.14.1"
}
}