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

Flow job add new child job during runtime or on complete #871

Closed
dturton opened this issue Nov 11, 2021 · 1 comment
Closed

Flow job add new child job during runtime or on complete #871

dturton opened this issue Nov 11, 2021 · 1 comment

Comments

@dturton
Copy link

dturton commented Nov 11, 2021

My use case is to be able to add additional child tasks when the initial child tasks are completed. Then using job.getChildrenValues() evaluate the results and decide to add additional child tasks to the job or not. I thought It should be possible by using the Job.create function and passing the parent {id and queue name}. I tried this method calling it from the parent job handler but I keep getting Missing key for parent job Is it possible to do this when the parent job is already active?

An example that I am working with is an e-commerce order cancelation. The first tas is to fetch the lastest order data based on the order number passed. Then based on certain properties such as the current status take additional actions such as checking the warehouse system to see if the order is already being worked on.

I saw a similar request on here #599

const q1Name = process.env.MAIN_QUEUE_NAME;
const q2Name = process.env.MAIN_TASK_QUEUE_NAME;

const q2 = new Queue(q2Name, {
  connection,
  defaultJobOptions: { removeOnComplete: false },
});

const flowHandler = async (job: Job) => {
  try {
    const newJob = await Job.create(
      q2,
      'STEP2',
      { orderNumber: 'STEP2' },
      {
        parent: {
          id: job.id,
          queue: q1Name,
        },
      }
    );
    return 'ok';
  } catch (error) {
    console.log(error);
    throw error;
  }
};

Thank you in advance.

@dturton
Copy link
Author

dturton commented Nov 11, 2021

Closing the issue as I realized that part of the issue is if the queue name is prefixed with 'bull' but when using Job.create it expects the fully qualified name. Will create a post under the Discussion.

@dturton dturton closed this as completed Nov 11, 2021
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

1 participant