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

[Flows] How to have multiple parents depend on the same child ? #2087

Closed
pbell23 opened this issue Jul 21, 2023 · 2 comments
Closed

[Flows] How to have multiple parents depend on the same child ? #2087

pbell23 opened this issue Jul 21, 2023 · 2 comments

Comments

@pbell23
Copy link

pbell23 commented Jul 21, 2023

Is your feature request related to a problem? Please describe.

I am implementing a flow in order to have an orderly execution of several jobs but I am facing a problem. I need the end of a child job to trigger the execution of several parents. How to do that ?

Describe the solution you'd like

I'll describe my problem with an example from the doc :

import { FlowProducer } from 'bullmq';
const flowProducer = new FlowProducer();

const queueName = 'assembly-line';
const chain = await flowProducer.add({
  name: 'car',
  data: { step: 'engine' },
  queueName,
  children: [
    {
      name: 'car',
      data: { step: 'wheels' },
      queueName,
      children: [{ name: 'car', data: { step: 'chassis' }, queueName }],
    },
  ],
});

The order of processing would be: 'chassis', 'wheels' and finally 'engine'.

Now let's say I want to add the job 'doors' that needs to start once 'chassis' is done at the same time 'wheels' starts. How am I suppose to make both 'wheels' and 'doors' depend on the same child 'chassis' ?

@roggervalf
Copy link
Collaborator

hi @pbell23, from the title, looks like a duplicate from #1021, but for your use case, you said you need to add a new job (doors) after chassis is done, you just need to add this doors job just before finishing chassis process as a workaround:

const worker = new Worker(
  'queueName',
  async (job: Job, token: string) => {
          //... some work
          await queueName.add(
            'car',
            { step: 'doors' }
          );
          return; // here you can return some result
  },
  { connection },
);

@pbell23
Copy link
Author

pbell23 commented Jul 23, 2023

hi @roggervalf this is indeed a duplicate. Thanks for linking it. As for the workaround, I think it will work but it takes away all the point of using flows because there is no longer a parent child relationship with the doors job.

I'll close this issue and follow #1021 .

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