Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jobs are added to the queue, nothing ever runs. #1171

Open
rdmorris opened this issue Jun 7, 2024 · 2 comments
Open

Jobs are added to the queue, nothing ever runs. #1171

rdmorris opened this issue Jun 7, 2024 · 2 comments

Comments

@rdmorris
Copy link

rdmorris commented Jun 7, 2024

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"
}
}

@MouadBH
Copy link

MouadBH commented Aug 1, 2024

I'm facing same issue, any update

@rdmorris
Copy link
Author

rdmorris commented Aug 1, 2024

Nope I pivoted to Inngest iircc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants