node.jsredisnext.js13bull

Trying to build a queue for Next js 13 with custom api ( bull, next.js, redis)


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.


Solution

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