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

When is resolved the Queue.process promise ? #1688

Closed
Zikoel opened this issue Apr 3, 2020 · 7 comments
Closed

When is resolved the Queue.process promise ? #1688

Zikoel opened this issue Apr 3, 2020 · 7 comments
Labels

Comments

@Zikoel
Copy link

Zikoel commented Apr 3, 2020

Hi, this is a question:

Is not clear for me when the returned promise from Queue.process is resolved, the process function is well documented but is not clear how to manage the process function return itself. If I write something like that:

queue.process('name', async job => {
    // Do the job
    }
).then( () => {
    console.log('processor added')
}

I don't event see the console log output!

@manast
Copy link
Member

manast commented Apr 4, 2020

in theory when the queue is closed.

@dprentis
Copy link

Could the method be synchronous or resolve directly?

Reason I'm asking is, typescript-eslint doesn't like ignoring the returned promise: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-floating-promises.md

(Although, as a workaround, it's simple to just disable the rule in place)

@Zikoel
Copy link
Author

Zikoel commented Jul 24, 2020

Return synchronously is not a real solution maybe under the hood there is a reason for the Promise. I think you can manage the promise like my example (don't wait for it) and just don't expect to see the debug! If that sounds to you like an hack maybe we can ask another version (sync) of the process method... if is it possible! Something like processSync

@dprentis
Copy link

I guess it's really a question of API design. Currently running process actually does two things - it sets the handler and then starts processing the queue.

It might be more intuitive to separate that eg. specify the handler in the Queue constructor (or in a separate method), and have process without parameters just start the processing.

Currently, attaching a 'then' or 'catch' to the call to process isn't that useful - I might as well just call process as if it were synchronous (but then typescript-eslint complains, so I have to disable it) eg.

// eslint-disable-next-line @typescript-eslint/no-floating-promises
queue.process('name', async job => {
    // Do the job
    }
)

@kbarendrecht
Copy link

This caught me by surprise aswell, it wasn't really clear to me that .process() starts processing as well as adding a processor. I started out by awaiting the .process() method because i didn't want the queue to start before i added a processor.

It would make it easier to grok when there are seperate methods, something like; .setProcessor(..), startProcessing(..)

@manast
Copy link
Member

manast commented Sep 15, 2020

yes. there are plans to improve the logic. In BullMQ for instance, the process is specified in the Worker constructor, so it is less confusing, however the processor starts processing directly after instantiating the worker, which is less code to type but more magic, which is not always good.

@stale
Copy link

stale bot commented Jul 12, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 12, 2021
@manast manast closed this as completed Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants