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

Reformat the code when semicolons enabled #275

Merged
merged 1 commit into from
May 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .prettierrc
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
}
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ module.exports = {
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-proposal-class-properties',
],
}
};
2 changes: 1 addition & 1 deletion bullAdapter.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { BullAdapter } from './dist/queueAdapters/bull'
export { BullAdapter } from './dist/queueAdapters/bull';
2 changes: 1 addition & 1 deletion bullAdapter.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./dist/queueAdapters/bull')
module.exports = require('./dist/queueAdapters/bull');
2 changes: 1 addition & 1 deletion bullMQAdapter.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { BullMQAdapter } from './dist/queueAdapters/bullMQ'
export { BullMQAdapter } from './dist/queueAdapters/bullMQ';
2 changes: 1 addition & 1 deletion bullMQAdapter.js
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');
99 changes: 50 additions & 49 deletions example.ts
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));
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ module.exports = {
},
testPathIgnorePatterns: ['/node_modules/'],
testMatch: ['<rootDir>/tests/**/*.spec.ts'],
}
};
6 changes: 3 additions & 3 deletions src/@types/api.ts
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[];
}
116 changes: 58 additions & 58 deletions src/@types/app.ts
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>;
}
4 changes: 2 additions & 2 deletions src/@types/global.ts
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;
}
2 changes: 1 addition & 1 deletion src/@types/utils.ts
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>;
Loading