Skip to content

Commit

Permalink
chore: Run prettier on all files
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroschmitz committed Jan 26, 2021
1 parent fb30aae commit 4bfd0b8
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 132 deletions.
47 changes: 25 additions & 22 deletions adonis-typings/bull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ declare module '@ioc:Rocketseat/Bull' {
export type BullConnectionContract = Exclude<
QueueOptions['connection'],
undefined
>;
>

/**
* A list of typed connections defined in the user land using
Expand All @@ -24,18 +24,18 @@ declare module '@ioc:Rocketseat/Bull' {
* everywhere.
*/
export interface BullConfig {
connection: keyof BullConnectionsList;
connections: { [P in keyof BullConnectionsList]: BullConnectionsList[P] };
connection: keyof BullConnectionsList
connections: { [P in keyof BullConnectionsList]: BullConnectionsList[P] }
}

export interface JobContract<T = any> {
key: string;
options?: JobsOptions;
workerOptions?: WorkerOptions;
queueOptions?: QueueOptions;
concurrency?: number;
handle: Processor;
boot?: (queue: Queue<T>) => void;
key: string
options?: JobsOptions
workerOptions?: WorkerOptions
queueOptions?: QueueOptions
concurrency?: number
handle: Processor
boot?: (queue: Queue<T>) => void
onCompleted?: (...args: any[]) => void
onProgress?: (...args: any[]) => void
onFailed?: (...args: any[]) => void
Expand All @@ -46,39 +46,42 @@ declare module '@ioc:Rocketseat/Bull' {
onDrained?: (...args: any[]) => void
}

export interface EventListener { eventName: string; method: string }
export interface EventListener {
eventName: string
method: string
}

export interface QueueContract<T = any> extends JobContract<T> {
bull: Queue<T>;
listeners: EventListener[];
instance: JobContract<T>;
bull: Queue<T>
listeners: EventListener[]
instance: JobContract<T>
}

export interface BullManagerContract {
queues: { [key: string]: QueueContract };
queues: { [key: string]: QueueContract }

getByKey(key: string): QueueContract;
getByKey(key: string): QueueContract

add<T>(
name: string,
data: T,
jobOptions?: JobsOptions
): Promise<Job<any, any>>;
): Promise<Job<any, any>>

schedule<T>(
name: string,
data: T,
date: number | Date,
jobOptions?: JobsOptions
): Promise<Job<any, any>>;
): Promise<Job<any, any>>

remove(name: string, jobId: string): Promise<void>;
remove(name: string, jobId: string): Promise<void>

ui(port?: number): void;
ui(port?: number): void

shutdown(): Promise<void>;
shutdown(): Promise<void>

process(): BullManagerContract;
process(): BullManagerContract
}

const Bull: BullManagerContract
Expand Down
6 changes: 3 additions & 3 deletions adonis-typings/exception-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ declare module '@ioc:Rocketseat/Bull/BullExceptionHandler' {
import { Job } from 'bullmq'

export default abstract class BullExceptionHandler {
constructor(logger: LoggerContract);
protected logger: LoggerContract;
public handle(error: any, ctx: Job): Promise<any>;
constructor(logger: LoggerContract)
protected logger: LoggerContract
public handle(error: any, ctx: Job): Promise<any>
}
}
14 changes: 10 additions & 4 deletions commands/Listen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default class Listen extends BaseCommand {
public static description = 'Start the Bull listener'
public static settings = {
loadApp: true,
stayAlive: true
stayAlive: true,
}

/**
Expand All @@ -17,20 +17,26 @@ export default class Listen extends BaseCommand {
/**
* Custom port for the bull-board
*/
@flags.number({ description: "Run bull's dashboard in the provided port", alias: 'p' })
@flags.number({
description: "Run bull's dashboard in the provided port",
alias: 'p',
})
public port: number

/**
* Execute command
*/
public async run (): Promise<void> {
public async run(): Promise<void> {
const bull = this.application.container.use('Rocketseat/Bull')

console.log({ board: this.board })

bull.process()

if (this.board || (typeof this.board === 'undefined' && typeof this.port !== 'undefined')) {
if (
this.board ||
(typeof this.board === 'undefined' && typeof this.port !== 'undefined')
) {
bull.ui(this.port)
}
}
Expand Down
2 changes: 1 addition & 1 deletion commands/MakeException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class MakeException extends BaseCommand {
/**
* Execute command
*/
public async run (): Promise<void> {
public async run(): Promise<void> {
const stub = join(__dirname, '..', 'templates', 'handler.txt')

const path = this.application.resolveNamespaceDirectory('exceptions')
Expand Down
7 changes: 5 additions & 2 deletions commands/MakeJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ export default class MakeJob extends BaseCommand {
/**
* Execute command
*/
public async run (): Promise<void> {
public async run(): Promise<void> {
const stub = join(__dirname, '..', 'templates', 'job.txt')
const jobName = new StringTransformer(this.name).changeCase('pascalcase').changeForm('singular').toValue()
const jobName = new StringTransformer(this.name)
.changeCase('pascalcase')
.changeForm('singular')
.toValue()

const path = this.application.resolveNamespaceDirectory('jobs')
const rootDir = this.application.cliCwd || this.application.appRoot
Expand Down
2 changes: 1 addition & 1 deletion commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default [
'@rocketseat/adonis-bull/build/commands/MakeJob',
'@rocketseat/adonis-bull/build/commands/MakeException',
'@rocketseat/adonis-bull/build/commands/Listen'
'@rocketseat/adonis-bull/build/commands/Listen',
]
67 changes: 49 additions & 18 deletions instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,45 @@ import { join } from 'path'
import * as sinkStatic from '@adonisjs/sink'
import { ApplicationContract } from '@ioc:Adonis/Core/Application'

function getStub (...relativePaths: string[]) {
function getStub(...relativePaths: string[]) {
return join(__dirname, 'templates', ...relativePaths)
}

export default async function instructions (
export default async function instructions(
projectRoot: string,
app: ApplicationContract,
sink: typeof sinkStatic
) {
const startMethod = await sink
.getPrompt()
.choice('How do you want to start your queue?',
[
{ name: 'command', message: 'Ace command', hint: 'Started by bull:listen command' }, { name: 'http', message: 'HTTP Server', hint: 'Started with the adonis server' }], {
validate (choice) {
return choice && choice.length ? true : 'Select a queue process start method'
}
})
const startMethod = await sink.getPrompt().choice(
'How do you want to start your queue?',
[
{
name: 'command',
message: 'Ace command',
hint: 'Started by bull:listen command',
},
{
name: 'http',
message: 'HTTP Server',
hint: 'Started with the adonis server',
},
],
{
validate(choice) {
return choice && choice.length
? true
: 'Select a queue process start method'
},
}
)

if (startMethod === 'http') {
const preloadFilePath = app.makePath('start/bull.ts')
const bullPreloadFile = new sink.files.MustacheFile(projectRoot, preloadFilePath, getStub('bull.txt'))
const bullPreloadFile = new sink.files.MustacheFile(
projectRoot,
preloadFilePath,
getStub('bull.txt')
)

bullPreloadFile.overwrite = true

Expand All @@ -38,7 +55,11 @@ export default async function instructions (
}

const configPath = app.configPath('bull.ts')
const bullConfig = new sink.files.MustacheFile(projectRoot, configPath, getStub('config.txt'))
const bullConfig = new sink.files.MustacheFile(
projectRoot,
configPath,
getStub('config.txt')
)

bullConfig.overwrite = true

Expand All @@ -48,20 +69,30 @@ export default async function instructions (
sink.logger.action('create').succeeded(`${configDir}/bull.ts`)

const contractsPath = app.makePath('contracts/bull.ts')
const bullContract = new sink.files.MustacheFile(projectRoot, contractsPath, getStub('contract.txt'))
const bullContract = new sink.files.MustacheFile(
projectRoot,
contractsPath,
getStub('contract.txt')
)
bullContract.overwrite = true

bullContract.commit()

sink.logger.action('create').succeeded('contracts/bull.ts')

const startsPath = app.makePath('start/jobs.ts')
const bullStart = new sink.files.MustacheFile(projectRoot, startsPath, getStub('start.txt'))
const bullStart = new sink.files.MustacheFile(
projectRoot,
startsPath,
getStub('start.txt')
)
bullStart.overwrite = true

bullStart.apply({
startJobs: []
}).commit()
bullStart
.apply({
startJobs: [],
})
.commit()

sink.logger.action('create').succeeded('start/jobs.ts')
}
6 changes: 3 additions & 3 deletions providers/BullProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { BullManagerContract } from '@ioc:Rocketseat/Bull'
* Provider to bind bull to the container
*/
export default class BullProvider {
constructor (protected container: IocContract) {}
constructor(protected container: IocContract) {}

public register () {
public register() {
this.container.bind('Rocketseat/Bull/BullExceptionHandler', () => {
const { BullExceptionHandler } = require('../src/BullExceptionHandler')
return BullExceptionHandler
Expand All @@ -27,7 +27,7 @@ export default class BullProvider {
this.container.alias('Rocketseat/Bull', 'Bull')
}

public async shutdown () {
public async shutdown() {
await this.container.use<BullManagerContract>('Rocketseat/Bull').shutdown()
}
}
4 changes: 2 additions & 2 deletions src/BullExceptionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { Job } from 'bullmq'
* lifecycle and makes appropriate response for them.
*/
export abstract class BullExceptionHandler {
constructor (protected logger: LoggerContract) {}
constructor(protected logger: LoggerContract) {}

public async handle (error: any, job: Job) {
public async handle(error: any, job: Job) {
if (typeof error.handle === 'function') {
return error.handle(error, job)
}
Expand Down
Loading

0 comments on commit 4bfd0b8

Please sign in to comment.