skip to Main Content

Hi developers i am trying to work on queue in next.js 13 with a custom api.

This is how far I got… the api is working the connection to redis is working but the middle is not working im trying to build the queue to learn and to grow for my personal project.

I’m stuck for 3 days now I did 1 script 2 script and a 3 script use that I just cut it in pieces, still no luck so I try my luck here.

im getting the following error:

Error: No .lua files found!
    at loadScripts (webpack-internal:///(rsc)/./node_modules/bull/lib/commands/index.js:29:15)
    at async eval (webpack-internal:///(rsc)/./node_modules/bull/lib/commands/index.js:18:19)
✅ Redis Connected Successfully

api/temp/route.js

import { NextResponse } from "next/server";
const Queue = require('bull');
import { connectToRedis } from "@/lib/redis";

export async function createQueue() {
  const redis = await connectToRedis();
  const queue = new Queue('my-queue', { redis: { client: redis, }, });
  return queue;
}

export async function addJob(queue, job) {
  await queue.add(job);
}

export async function POST(request) {
  try {
    const queue = await createQueue();
    await addJob(queue, { name: "John", age: 30 });
    return NextResponse.json({ message: "Hello, redis, bull API" }, { status: 200 });
  } catch (error) {
    console.log(error);
    return NextResponse.json({ message: "An error occured by creating a que."}, { status: 500 });
  }
}

second try:

const Queue = require('bull');
import { connectToRedis } from "@/lib/redis";

export async function createQueue() {
  const redis = await connectToRedis();
  const queue = new Queue('my-queue', { redis: { client: redis, }, });
  return queue;
}

export async function addJob(queue, job) {
  await queue.add(job);
}
import { NextResponse } from "next/server";
import Queue from "bull";
import { createQueue, addJob } from "@/lib/queue";

export async function POST(request) {
  try {
    const queue = await createQueue();
    await addJob(queue, { name: "John", age: 30 });
    return NextResponse.json({ message: "Hello, redis, bull API" }, { status: 200 });
  } catch (error) {
    console.log(error);
    return NextResponse.json({ message: "An error occured by creating a que."}, { status: 500 });
  }
}

I tried google the awnser, read all the website off the used software but still no luck at all.

2

Answers


  1. Chosen as BEST ANSWER

    I figured this out with bull. but we made a switch to bullmq with a spin off using a redis with handling temporary jobs.


  2. The best way to get background jobs working with Next.js is by using the experimental instrumentation.

    Docs here: https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation

    I have also written a more detailed blog post on how to get setup with bullmq and the latest Next.js: https://medium.com/@mofaddelzakaria/nextjs-with-bullmq-fc25aa7b8fe5

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search