question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add new sibling job in flow at runtime

See original GitHub issue

As a worker, I’d like to be able to inject a new job into a flow at the same level as the current job (same parentId) I tried just creating a new job with the same parentId via JobsOptions.parent but the parent job still ran before the new child. Any advice on how to get my desired behavior?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
roggervalfcommented, Feb 3, 2022

hi @blankenshipz, I modified your first example a little bit, there were some data that were passed in an incorrect way:

it('should process children before the parent when jobs have been added to the flow at runtime', async () => {
    const name = 'child-job';
    const values = [
      { bar: 'something' },
      { baz: 'something' },
      { qux: 'something' },
    ];

    const parentQueueName = `parent-queue-${v4()}`;

    let childrenProcessor,
      parentProcessor,
      processedChildren = 0;

    const processingChildren = new Promise<void>(
      resolve =>
        (childrenProcessor = async (job: Job) => {
          processedChildren++;

          if(processedChildren == 1) {
            await queue.add(name, {  qux: 'something', idx: 2}, 
            {parent:{ id: job?.parent.id, queue: `bull:${parentQueueName}`}});
          }

          console.log("Processing:  " + job.data.idx);

          if(processedChildren == 3) {
            resolve();
          }
          return job.data.idx;
        }),
    );

    const processingParent = new Promise<void>((resolve, reject) => [
      (parentProcessor = async (job: Job) => {
        try {
          const { processed, nextProcessedCursor } = await job.getDependencies({
            processed: {},
          });

          expect(nextProcessedCursor).to.be.equal(0);
          expect(Object.keys(processed)).to.have.length(3);
          resolve();
        } catch (err) {
          console.error(err);
          reject(err);
        }
      }),
    ]);

    const parentWorker = new Worker(parentQueueName, parentProcessor, {
      connection,
    });
    const childrenWorker = new Worker(queueName, childrenProcessor, {
      connection,
    });
    await parentWorker.waitUntilReady();
    await childrenWorker.waitUntilReady();

    const flow = new FlowProducer({ connection });
    const tree = await flow.add({
      name: 'parent-job',
      queueName: parentQueueName,
      data: {},
      children: [
        { name, data: { idx: 0, foo: 'bar' }, queueName },
        { name, data: { idx: 1, foo: 'baz' }, queueName },
      ],
    });

    expect(tree).to.have.property('job');
    expect(tree).to.have.property('children');

    const { job } = tree;
    const parentState = await job.getState();

    expect(parentState).to.be.eql('waiting-children');

    await processingChildren;
    await childrenWorker.close();
    const dependencyCount = await job.getDependenciesCount();

    expect(dependencyCount.processed).to.eql(3);

    await processingParent;
    await parentWorker.close();

    await flow.close();
    await removeAllQueueData(new IORedis(), parentQueueName);
  });

this one is working

0reactions
roggervalfcommented, May 5, 2022

As we have a pattern to handle step jobs, this issue could be closed I think

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flows and Subflows | MuleSoft Documentation
Mule applications are built around one or more flows. Typically, a Mule application begins processing a message it receives at an inbound endpoint...
Read more >
Adjacent sibling combinator - CSS: Cascading Style Sheets
The adjacent sibling combinator ( + ) separates two selectors and matches the second element only if it immediately follows the first element, ......
Read more >
Multi-node parallel jobs - AWS Batch
You can use multi-node parallel jobs to run single jobs that span multiple Amazon EC2 instances. With AWS Batch multi-node parallel jobs, ...
Read more >
Azkaban 3.0 Documentation
Previous Flow/Jobs - Search through previous executions of jobs and flows as well as access ... added to Azkaban properties during runtime for...
Read more >
java - How to programmatically add views and constraints to a ...
ConstraintLayout layout = (ConstraintLayout) findViewById(R.id.mainConstraint); ConstraintSet set = new ConstraintSet(); set.clone(layout); ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found