quirrel-dev / quirrel

The Task Queueing Solution for Serverless.
https://quirrel.dev
MIT License
892 stars 67 forks source link

Executing Job using Nextjs App Router not working correctly #1156

Closed jandmc closed 1 year ago

jandmc commented 1 year ago

Bug Report

Current Behavior I am migrating to nextjs AppRouter. After I adapted my quirrel jobs (so moving to new directory and exporting ist correctly) Invoking a Job in Nextjs AppRouter (using quirell dev server ui) sometimes works, sometimes not. Depending on the name of the route. In case I found a naming which worked, it doesn't matter which code a put inside the handler function it just works as exepected.

Input Code

File in directory src/app/api/cronjobs/sample/route.ts

import { CronJob } from "quirrel/next";

const job = CronJob("api/cronjobs/sample", "*/60 * * * *", async () => {
  console.log("Executed");
});
export const POST = job;

Expected behavior/code I would expect that the jobs just work as before using nextjs pages router. Strange is that if I move the payload code of a non working job into the handler of a working one, the code works as expected. Maybe something with caching the routes is broken?!

Environment

Additional context/Screenshots . quirrel_issue

Skn0tt commented 1 year ago

If you use the Next Route Handlers (as your code snippet indicates), then you'll have to use it with Quirrel's Next.js App Router adapter. Try replacing import { CronJob } from "quirrel/next" with import { CronJob } from "quirrel/next-app".

jandmc commented 1 year ago

Thanks for that hint! It is now working. Even with pages/api jobs in parallel to approuter/api jobs.