Skip to content

Commit

Permalink
add flow endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmosh committed Mar 28, 2024
1 parent 5a71520 commit 811ec53
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion example.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Bull from 'bull';
import Queue3 from 'bull';
import { Queue as QueueMQ, Worker } from 'bullmq';
import { Queue as QueueMQ, Worker, FlowProducer } from 'bullmq';
import express from 'express';
import { BullMQAdapter } from '@bull-board/api/src/queueAdapters/bullMQ';
import { BullAdapter } from '@bull-board/api/src/queueAdapters/bull';
Expand Down Expand Up @@ -54,6 +54,7 @@ const run = async () => {

const exampleBull = createQueue3('ExampleBull');
const exampleBullMq = createQueueMQ('ExampleBullMQ');
const flow = new FlowProducer({ connection: redisOptions });

await setupBullProcessor(exampleBull); // needed only for example proposes
await setupBullMQProcessor(exampleBullMq.name); // needed only for example proposes
Expand All @@ -71,7 +72,60 @@ const run = async () => {

exampleBull.add({ title: req.query.title }, opts);
exampleBullMq.add('Add', { title: req.query.title }, opts);
res.json({
ok: true,
});
});

app.use('/add-flow', (req, res) => {
const opts = req.query.opts || ({} as any);

if (opts.delay) {
opts.delay = +opts.delay * 1000; // delay must be a number
}

if (opts.priority) {
opts.priority = +opts.priority;
}

flow.add({
name: 'root-job',
queueName: 'ExampleBullMQ',
data: {},
opts,
children: [
{
name: 'job-child1',
data: { idx: 0, foo: 'bar' },
queueName: 'ExampleBullMQ',
opts,
children: [
{
name: 'job-grandchildren1',
data: { idx: 4, foo: 'baz' },
queueName: 'ExampleBullMQ',
opts,
children: [
{
name: 'job-child2',
data: { idx: 2, foo: 'foo' },
queueName: 'ExampleBullMQ',
opts,
children: [
{
name: 'job-child3',
data: { idx: 3, foo: 'bis' },
queueName: 'ExampleBullMQ',
opts,
},
],
},
],
},
],
},
],
});
res.json({
ok: true,
});
Expand Down

0 comments on commit 811ec53

Please sign in to comment.