-
-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
80 changed files
with
3,672 additions
and
1,306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"arrowParens": "always" | ||
"trailingComma": "es5", | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { BullAdapter } from './dist/queueAdapters/bull' | ||
export { BullAdapter } from './dist/queueAdapters/bull'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
module.exports = require('./dist/queueAdapters/bull') | ||
module.exports = require('./dist/queueAdapters/bull'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { BullMQAdapter } from './dist/queueAdapters/bullMQ' | ||
export { BullMQAdapter } from './dist/queueAdapters/bullMQ'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
/// <reference path="./dist/queueAdapters/bullMQ.d.ts" /> | ||
module.exports = require('./dist/queueAdapters/bullMQ') | ||
module.exports = require('./dist/queueAdapters/bullMQ'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,97 @@ | ||
import * as Bull from 'bull' | ||
import Queue3 from 'bull' | ||
import { Queue as QueueMQ, QueueScheduler, Worker } from 'bullmq' | ||
import express from 'express' | ||
import { createBullBoard } from './src' | ||
import { BullAdapter } from './src/queueAdapters/bull' | ||
import { BullMQAdapter } from './src/queueAdapters/bullMQ' | ||
import * as Bull from 'bull'; | ||
import Queue3 from 'bull'; | ||
import { Queue as QueueMQ, QueueScheduler, Worker } from 'bullmq'; | ||
import express from 'express'; | ||
import { createBullBoard } from './src'; | ||
import { BullAdapter } from './src/queueAdapters/bull'; | ||
import { BullMQAdapter } from './src/queueAdapters/bullMQ'; | ||
|
||
const redisOptions = { | ||
port: 6379, | ||
host: 'localhost', | ||
password: '', | ||
} | ||
}; | ||
|
||
const sleep = (t: number) => | ||
new Promise((resolve) => setTimeout(resolve, t * 1000)) | ||
new Promise((resolve) => setTimeout(resolve, t * 1000)); | ||
|
||
const createQueue3 = (name: string) => new Queue3(name, { redis: redisOptions }) | ||
const createQueue3 = (name: string) => | ||
new Queue3(name, { redis: redisOptions }); | ||
const createQueueMQ = (name: string) => | ||
new QueueMQ(name, { connection: redisOptions }) | ||
new QueueMQ(name, { connection: redisOptions }); | ||
|
||
function setupBullProcessor(bullQueue: Bull.Queue) { | ||
bullQueue.process(async (job) => { | ||
for (let i = 0; i <= 100; i++) { | ||
await sleep(Math.random()) | ||
await job.progress(i) | ||
await job.log(`Processing job at interval ${i}`) | ||
if (Math.random() * 200 < 1) throw new Error(`Random error ${i}`) | ||
await sleep(Math.random()); | ||
await job.progress(i); | ||
await job.log(`Processing job at interval ${i}`); | ||
if (Math.random() * 200 < 1) throw new Error(`Random error ${i}`); | ||
} | ||
|
||
return { jobId: `This is the return value of job (${job.id})` } | ||
}) | ||
return { jobId: `This is the return value of job (${job.id})` }; | ||
}); | ||
} | ||
|
||
async function setupBullMQProcessor(queueName: string) { | ||
const queueScheduler = new QueueScheduler(queueName, { | ||
connection: redisOptions, | ||
}) | ||
await queueScheduler.waitUntilReady() | ||
}); | ||
await queueScheduler.waitUntilReady(); | ||
|
||
new Worker(queueName, async (job) => { | ||
for (let i = 0; i <= 100; i++) { | ||
await sleep(Math.random()) | ||
await job.updateProgress(i) | ||
await job.log(`Processing job at interval ${i}`) | ||
await sleep(Math.random()); | ||
await job.updateProgress(i); | ||
await job.log(`Processing job at interval ${i}`); | ||
|
||
if (Math.random() * 200 < 1) throw new Error(`Random error ${i}`) | ||
if (Math.random() * 200 < 1) throw new Error(`Random error ${i}`); | ||
} | ||
|
||
return { jobId: `This is the return value of job (${job.id})` } | ||
}) | ||
return { jobId: `This is the return value of job (${job.id})` }; | ||
}); | ||
} | ||
|
||
const run = async () => { | ||
const app = express() | ||
const app = express(); | ||
|
||
const exampleBull = createQueue3('ExampleBull') | ||
const exampleBullMq = createQueueMQ('ExampleBullMQ') | ||
const exampleBull = createQueue3('ExampleBull'); | ||
const exampleBullMq = createQueueMQ('ExampleBullMQ'); | ||
|
||
await setupBullProcessor(exampleBull) // needed only for example proposes | ||
await setupBullMQProcessor(exampleBullMq.name) // needed only for example proposes | ||
await setupBullProcessor(exampleBull); // needed only for example proposes | ||
await setupBullMQProcessor(exampleBullMq.name); // needed only for example proposes | ||
|
||
app.use('/add', (req, res) => { | ||
const opts = req.query.opts || ({} as any) | ||
const opts = req.query.opts || ({} as any); | ||
|
||
if (opts.delay) { | ||
opts.delay = +opts.delay * 1000 // delay must be a number | ||
opts.delay = +opts.delay * 1000; // delay must be a number | ||
} | ||
|
||
exampleBull.add({ title: req.query.title }, opts) | ||
exampleBullMq.add('Add', { title: req.query.title }, opts) | ||
exampleBull.add({ title: req.query.title }, opts); | ||
exampleBullMq.add('Add', { title: req.query.title }, opts); | ||
|
||
res.json({ | ||
ok: true, | ||
}) | ||
}) | ||
}); | ||
}); | ||
|
||
const { router: bullBoardRouter } = createBullBoard([ | ||
new BullMQAdapter(exampleBullMq), | ||
new BullAdapter(exampleBull), | ||
]) | ||
]); | ||
|
||
app.use('/ui', bullBoardRouter) | ||
app.use('/ui', bullBoardRouter); | ||
|
||
app.listen(3000, () => { | ||
console.log('Running on 3000...') | ||
console.log('For the UI, open http://localhost:3000/ui') | ||
console.log('Make sure Redis is running on port 6379 by default') | ||
console.log('To populate the queue, run:') | ||
console.log(' curl http://localhost:3000/add?title=Example') | ||
console.log('To populate the queue with custom options (opts), run:') | ||
console.log(' curl http://localhost:3000/add?title=Test&opts[delay]=10') | ||
}) | ||
} | ||
|
||
run().catch((e) => console.error(e)) | ||
console.log('Running on 3000...'); | ||
console.log('For the UI, open http://localhost:3000/ui'); | ||
console.log('Make sure Redis is running on port 6379 by default'); | ||
console.log('To populate the queue, run:'); | ||
console.log(' curl http://localhost:3000/add?title=Example'); | ||
console.log('To populate the queue with custom options (opts), run:'); | ||
console.log(' curl http://localhost:3000/add?title=Test&opts[delay]=10'); | ||
}); | ||
}; | ||
|
||
run().catch((e) => console.error(e)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { ValidMetrics, AppQueue } from './app' | ||
import { AppQueue, ValidMetrics } from './app'; | ||
|
||
export interface GetQueues { | ||
stats: Partial<ValidMetrics> | ||
queues: AppQueue[] | ||
stats: Partial<ValidMetrics>; | ||
queues: AppQueue[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,96 @@ | ||
import { BaseAdapter } from '../queueAdapters/base' | ||
import { Status } from '../ui/components/constants' | ||
import { BaseAdapter } from '../queueAdapters/base'; | ||
import { Status } from '../ui/components/constants'; | ||
|
||
export type JobCleanStatus = | ||
| 'completed' | ||
| 'wait' | ||
| 'active' | ||
| 'delayed' | ||
| 'failed' | ||
| 'failed'; | ||
|
||
export type JobStatus = Status | ||
export type JobStatus = Status; | ||
|
||
export type JobCounts = Record<JobStatus, number> | ||
export type JobCounts = Record<JobStatus, number>; | ||
|
||
export interface QueueAdapterOptions { | ||
readOnlyMode: boolean | ||
readOnlyMode: boolean; | ||
} | ||
|
||
export type BullBoardQueues = Map<string, BaseAdapter> | ||
export type BullBoardQueues = Map<string, BaseAdapter>; | ||
|
||
export interface QueueJob { | ||
opts: { | ||
delay?: number | undefined | ||
} | ||
delay?: number | undefined; | ||
}; | ||
|
||
promote(): Promise<void> | ||
promote(): Promise<void>; | ||
|
||
remove(): Promise<void> | ||
remove(): Promise<void>; | ||
|
||
retry(): Promise<void> | ||
retry(): Promise<void>; | ||
|
||
toJSON(): QueueJobJson | ||
toJSON(): QueueJobJson; | ||
} | ||
|
||
export interface QueueJobJson { | ||
// add properties as needed from real Bull/BullMQ jobs | ||
id?: string | undefined | number | null | ||
name: string | ||
id?: string | undefined | number | null; | ||
name: string; | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
progress: number | object | ||
attemptsMade: number | ||
finishedOn?: number | null | ||
processedOn?: number | null | ||
timestamp: number | ||
failedReason: string | ||
stacktrace: string[] | null | ||
data: any | ||
returnvalue: any | ||
opts: any | ||
parentKey?: string | ||
progress: number | object; | ||
attemptsMade: number; | ||
finishedOn?: number | null; | ||
processedOn?: number | null; | ||
timestamp: number; | ||
failedReason: string; | ||
stacktrace: string[] | null; | ||
data: any; | ||
returnvalue: any; | ||
opts: any; | ||
parentKey?: string; | ||
} | ||
|
||
export interface ValidMetrics { | ||
total_system_memory: string | ||
redis_version: string | ||
used_memory: string | ||
mem_fragmentation_ratio: string | ||
connected_clients: string | ||
blocked_clients: string | ||
total_system_memory: string; | ||
redis_version: string; | ||
used_memory: string; | ||
mem_fragmentation_ratio: string; | ||
connected_clients: string; | ||
blocked_clients: string; | ||
} | ||
|
||
export interface AppJob { | ||
id: QueueJobJson['id'] | ||
name: QueueJobJson['name'] | ||
timestamp: QueueJobJson['timestamp'] | ||
processedOn?: QueueJobJson['processedOn'] | ||
finishedOn?: QueueJobJson['finishedOn'] | ||
progress: QueueJobJson['progress'] | ||
attempts: QueueJobJson['attemptsMade'] | ||
failedReason: QueueJobJson['failedReason'] | ||
stacktrace: string[] | ||
delay: number | undefined | ||
opts: QueueJobJson['opts'] | ||
data: QueueJobJson['data'] | ||
returnValue: QueueJobJson['returnvalue'] | ||
id: QueueJobJson['id']; | ||
name: QueueJobJson['name']; | ||
timestamp: QueueJobJson['timestamp']; | ||
processedOn?: QueueJobJson['processedOn']; | ||
finishedOn?: QueueJobJson['finishedOn']; | ||
progress: QueueJobJson['progress']; | ||
attempts: QueueJobJson['attemptsMade']; | ||
failedReason: QueueJobJson['failedReason']; | ||
stacktrace: string[]; | ||
delay: number | undefined; | ||
opts: QueueJobJson['opts']; | ||
data: QueueJobJson['data']; | ||
returnValue: QueueJobJson['returnvalue']; | ||
} | ||
|
||
export interface AppQueue { | ||
name: string | ||
counts: Record<Status, number> | ||
jobs: AppJob[] | ||
readOnlyMode: boolean | ||
name: string; | ||
counts: Record<Status, number>; | ||
jobs: AppJob[]; | ||
readOnlyMode: boolean; | ||
} | ||
|
||
export type SelectedStatuses = Record<AppQueue['name'], Status> | ||
export type SelectedStatuses = Record<AppQueue['name'], Status>; | ||
|
||
export interface QueueActions { | ||
promoteJob: (queueName: string) => (job: AppJob) => () => Promise<void> | ||
retryJob: (queueName: string) => (job: AppJob) => () => Promise<void> | ||
cleanJob: (queueName: string) => (job: AppJob) => () => Promise<void> | ||
getJobLogs: (queueName: string) => (job: AppJob) => () => Promise<string[]> | ||
retryAll: (queueName: string) => () => Promise<void> | ||
cleanAllDelayed: (queueName: string) => () => Promise<void> | ||
cleanAllFailed: (queueName: string) => () => Promise<void> | ||
cleanAllCompleted: (queueName: string) => () => Promise<void> | ||
promoteJob: (queueName: string) => (job: AppJob) => () => Promise<void>; | ||
retryJob: (queueName: string) => (job: AppJob) => () => Promise<void>; | ||
cleanJob: (queueName: string) => (job: AppJob) => () => Promise<void>; | ||
getJobLogs: (queueName: string) => (job: AppJob) => () => Promise<string[]>; | ||
retryAll: (queueName: string) => () => Promise<void>; | ||
cleanAllDelayed: (queueName: string) => () => Promise<void>; | ||
cleanAllFailed: (queueName: string) => () => Promise<void>; | ||
cleanAllCompleted: (queueName: string) => () => Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
declare module '*.css' { | ||
const resource: Record<string, string> | ||
export = resource | ||
const resource: Record<string, string>; | ||
export = resource; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export type KeyOf<T> = Array<keyof T> | ||
export type KeyOf<T> = Array<keyof T>; |
Oops, something went wrong.