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

Infinite Loop #4

Open
nahtnam opened this issue Jun 14, 2024 · 3 comments
Open

Infinite Loop #4

nahtnam opened this issue Jun 14, 2024 · 3 comments

Comments

@nahtnam
Copy link

nahtnam commented Jun 14, 2024

Hey! My project uses prisma and this looked pretty convenient so I wanted to give it a shot.

I'm facing an issue where the worker is getting stuck in an infinite loop. As soon as I add a job, it prints out an infinite amount of:

2024-06-14T06:50:14.123Z prisma-queue processing job from queue named="email"...
2024-06-14T06:50:14.123Z prisma-queue dequeuing from queue named="email"...
2024-06-14T06:50:14.124Z prisma-queue no jobs found in queue named="email"
2024-06-14T06:50:14.174Z prisma-queue processing job from queue named="email"...
2024-06-14T06:50:14.174Z prisma-queue dequeuing from queue named="email"...
2024-06-14T06:50:14.175Z prisma-queue no jobs found in queue named="email"

I noticed that in the DB, the job is not being removed. NOTE: I'm not awaiting the .start()

Code:

export const emailQueue = createQueue<JobPayload, JobResult>(
  { name: 'email' },
  async (job, client) => {
    const { id, payload } = job;
    console.log(
      `Processing job#${id} with payload=${JSON.stringify(payload)})`,
    );
    // await someAsyncMethod();
    await job.progress(50);
    const status = 200;
    if (Math.random() > 0.5) {
      throw new Error(`Failed for some unknown reason`);
    }
    console.log(`Finished job#${id} with status=${status}`);
    return { status };
  },
);

void emailQueue.start();

My use case is I'm running Next.js in a container and just want this to run in the background. So I just put the void emailQueue.start() so that it does it in the background. This strategy seems to work with pgboss

@mgcrea
Copy link
Owner

mgcrea commented Jun 14, 2024

When using pgboss do you await boss.work()? Looks like the process is killed and respawned very quickly and do not have time to actually process the job, you should await queue.start() when using prisma queue (which is basically the equivalent of boss.work).

@nahtnam
Copy link
Author

nahtnam commented Jun 14, 2024

No, I wrote the code in the same way with void in the top level

@nahtnam
Copy link
Author

nahtnam commented Jun 14, 2024

Got it to work!

async function init() {
  await emailQueue.start();
}

void init()

Do you foresee any problems with this?

EDIT: nvm, still seems to infinite loop

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