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

New worker implementation doesn't return result to job instigator #775

Closed
chladog opened this issue Mar 20, 2021 · 1 comment
Closed

New worker implementation doesn't return result to job instigator #775

chladog opened this issue Mar 20, 2021 · 1 comment
Assignees
Labels
type: bug 🐛 Something isn't working

Comments

@chladog
Copy link
Contributor

chladog commented Mar 20, 2021

Describe the bug
In the new worker implementation, there is no way to subscribe to job result.

Expected behavior
A feature that would allow us to subscribe to job process and its full resulting value, or at least some identifier (e.g. filepath).

Environment (please complete the following information):

  • @vendure/core version: v1.0.beta3

Additional context
We use worker for heavy tasks even in normal request/response cycle. For example user requests new PDF invoice, task is handled over to worker and then we want to send the PDF file to the user when it's ready.

@chladog chladog added the type: bug 🐛 Something isn't working label Mar 20, 2021
@michaelbromley
Copy link
Member

Outlining the problem to solve: with the old microservices architecture, it was straightforward because the code that created the job (jobQueue.add()) was running in the same process that also dispatched the work to the worker, and the NestJS microservice allowed us to send messages back to the server.

Now we have a pure job queue, there is no built-in communication channel from worker -> server.

So the basic mechanism of being able to get the results of a worker job would go like this:

  1. Create a job with jobQueue.add(). In the DefaultJobQueuePlugin we'd get a Job object back which had an ID of the row in the DB.
  2. To subscribe to the results of that job, we'd then need to poll the DB for changes to that job. Since we have the ID, this is a very simple and light query. When polling, we inspect the Job state, result and error properties and when we find changes we can register that the Job updated (completed or failed).
  3. We don't want to trigger polling for all jobs. Only when needed. So we need some way to lazily trigger polling only when the code actually requires the result of the job. Using an observable would work well here since they are lazily evaluated (will only execute if subscribed to).

Other JobQueueStrategies (e.g. Google Pub/Sub) don't have any means of transmitting data back to the caller, so we'd need to have this capability dependent on the strategy (e.g. throw an error when someone attempts to subscribe to the result of a Job where the strategy does not support it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants