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

How to access the bullmq job in the Job class handler #46

Open
p3drosola opened this issue Jun 10, 2024 · 5 comments
Open

How to access the bullmq job in the Job class handler #46

p3drosola opened this issue Jun 10, 2024 · 5 comments
Assignees

Comments

@p3drosola
Copy link

In the v2 version of this library for adonis v5, to access the bullmq job you could access this.job in the handler function.

I've checked the source and can see the #bullMqJob private variable, but it's not accesible by the classes that inherit from Job.

Would you accept a pr for a getJob function, or a making the variable public?

@RomainLanz
Copy link
Owner

Hey @p3drosola! 👋🏻

What's your use case for accessing the job instance?
I would rather create a proper getter for your use case than give direct access to the BullMQ Job instance. Why? Because I may want to create a proper abstraction in the future so we can have a "real" queue package, and being deeply linked to BullMQ will not help. 😄

@rutonyru
Copy link

rutonyru commented Jun 10, 2024

Hi,
Ok. That's why I can not access to the job in my handle function. You're doing a pretty good job and of course, I understand the reason why. Even I can't wait for a "good solution", I can also describe my use case.
My use case could be :
My job can be a "waiting job" to access to an asynchronous data (slow integration of a file in a document manager). I decided to init the job with 5 attempts and a waiting delay of 5000ms :

  • So my handle function will have to manage the loss of the document (the document is deleted by the user before the end of the process) => "moveToFailed".
  • The job found that the integration is still processing : => go on (not an error, not a success), next time job ? exit from the function ?
  • The handle found that the doc integration is finished with success => End of the job with sucess. moveToSuccess() (and launch an other job to get the doc info)
  • The handle found that the doc integration is finished with an error => moveToFailed
    Thanks,
    Antoine
    PS : Even if you plan to have an adonis queue manager (with abstraction of the engine), will it be in this repo : adonis-bull-queue ?

@rutonyru rutonyru mentioned this issue Jun 10, 2024
@p3drosola
Copy link
Author

p3drosola commented Jun 10, 2024

In my case in particular I need:

  • job.name
  • job.stacktrace (in the failure handler, to report the error to my error tracker)
  • job.repeatJobKey for logging
  • job.id for logging
  • job.log function

I understand the desire to provide a generic job queue wrapper, but for now It'd be preferable not cripple the bullmq functionality, and allow us to access the bullmq job object directly since this abstraction:

a) does not support other job queues
b) does not even attempt to provide the full bullmq api surface area

@RomainLanz
Copy link
Owner

You are right. Better off leveraging BullMQ than trying to create a bad abstraction for now.

It will be available using this.getJob() inside the handle or rescue method.

@p3drosola
Copy link
Author

Hi @RomainLanz ,

I'm taking another stab at upgrading my app. I saw you added the getJob method but the latest version on NPM doesn't include it. Any chance you could publish a new version?

Thanks in advance!

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

No branches or pull requests

3 participants