-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added cleanupJobAfterCollection flag
- Loading branch information
1 parent
3b8c7e4
commit 8e2fe26
Showing
11 changed files
with
220 additions
and
160 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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { get } from 'env-var'; | ||
|
||
export default () => { | ||
return { | ||
cleanupJobAfterCollected: get('CLEANUP_JOB_AFTER_COLLECTED') | ||
.default('false') | ||
.asBool(), | ||
}; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ApiPropertyOptional } from '@nestjs/swagger'; | ||
import { Transform } from 'class-transformer'; | ||
import { IsOptional } from 'class-validator'; | ||
import { PrintUrlOptionalDto } from './print-url-optional.dto'; | ||
|
||
export class PrintUrlCollectOptionalDto extends PrintUrlOptionalDto { | ||
@Transform(({ value }) => value === 'true') | ||
@IsOptional() | ||
@ApiPropertyOptional({ | ||
description: 'Cleanup job data.', | ||
default: false, | ||
}) | ||
cleanupJob: boolean = false; | ||
} |
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
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,14 +1,23 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { JwtModule } from '@nestjs/jwt'; | ||
|
||
import { ConfigModule } from '@nestjs/config'; | ||
import { WhateverModule } from 'src/whatever/whatever.module'; | ||
import { QueueModule } from '../queue/queue.module'; | ||
import configuration from './collect.configuration'; | ||
import { CollectController } from './collect.controller'; | ||
import { PrintNowController } from './print-now.controller'; | ||
import { PrintSoonController } from './print-soon.controller'; | ||
|
||
@Module({ | ||
imports: [JwtModule, QueueModule, WhateverModule], | ||
imports: [ | ||
JwtModule, | ||
QueueModule, | ||
WhateverModule, | ||
ConfigModule.forRoot({ | ||
load: [configuration], | ||
}), | ||
], | ||
controllers: [PrintNowController, PrintSoonController, CollectController], | ||
}) | ||
export class PrintModule {} |
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
136 changes: 68 additions & 68 deletions
136
src/queue/queue.consumer.ts → src/queue/printer-queue.consumer.ts
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,68 +1,68 @@ | ||
import { | ||
InjectQueue, | ||
OnQueueCompleted, | ||
OnQueueFailed, | ||
Process, | ||
Processor, | ||
} from '@nestjs/bull'; | ||
import { Job, Queue } from 'bull'; | ||
import { get } from 'env-var'; | ||
|
||
import { Logger } from '@nestjs/common'; | ||
import { PrintStep } from '../pagedjs/print-step.enum'; | ||
import { PrintOptions } from '../whatever/print-options.interface'; | ||
import { PrintServiceFactory } from '../whatever/print.service.factory'; | ||
import { JobReturnValue } from './job-return-value.interface'; | ||
|
||
@Processor({ name: 'printer' }) | ||
export class QueueConsumer { | ||
private readonly logger = new Logger(QueueConsumer.name); | ||
|
||
constructor( | ||
private readonly printServiceFactory: PrintServiceFactory, | ||
@InjectQueue('callbacker') private callbackQueue: Queue, | ||
) {} | ||
|
||
@Process({ | ||
name: 'print', | ||
concurrency: get('QUEUE_CONCURRENCY').default(1).asIntPositive(), // TODO: hmmmmmmmmm | ||
}) | ||
async transcode(job: Job<PrintOptions>): Promise<JobReturnValue> { | ||
this.logger.log(`Process job ${job.id}`); | ||
|
||
const printService = this.printServiceFactory.create(job.data.outputType); | ||
|
||
const data = await printService.print( | ||
job.data.input, | ||
job.data.additionalScripts, | ||
job.data.timeout, | ||
job.data.injectPolyfill, | ||
job.data.httpHeaders, | ||
async (step: PrintStep) => await job.progress(step.toString()), | ||
); | ||
|
||
return { data, outputType: job.data.outputType }; | ||
} | ||
|
||
@OnQueueCompleted({ name: 'print' }) | ||
completedHandler(job: Job) { | ||
this.logger.log(`Finished print ${job.id}`); | ||
|
||
this.processHandler(job); | ||
} | ||
|
||
@OnQueueFailed({ name: 'print' }) | ||
failedHandler(job: Job, e: Error) { | ||
this.logger.error(`Failed print ${job.id}`, e); | ||
|
||
this.processHandler(job); | ||
} | ||
|
||
private processHandler(job: Job) { | ||
if (job.data.callbackUrl) { | ||
this.logger.log(`Addin callback job for print job ${job.id}`); | ||
|
||
this.callbackQueue.add('callback', job.id); | ||
} | ||
} | ||
} | ||
import { | ||
InjectQueue, | ||
OnQueueCompleted, | ||
OnQueueFailed, | ||
Process, | ||
Processor, | ||
} from '@nestjs/bull'; | ||
import { Job, Queue } from 'bull'; | ||
import { get } from 'env-var'; | ||
|
||
import { Logger } from '@nestjs/common'; | ||
import { PrintStep } from '../pagedjs/print-step.enum'; | ||
import { PrintOptions } from '../whatever/print-options.interface'; | ||
import { PrintServiceFactory } from '../whatever/print.service.factory'; | ||
import { JobReturnValue } from './job-return-value.interface'; | ||
|
||
@Processor({ name: 'printer' }) | ||
export class PrinterQueueConsumer { | ||
private readonly logger = new Logger(PrinterQueueConsumer.name); | ||
|
||
constructor( | ||
private readonly printServiceFactory: PrintServiceFactory, | ||
@InjectQueue('callbacker') private callbackerQueue: Queue, | ||
) {} | ||
|
||
@Process({ | ||
name: 'print', | ||
concurrency: get('QUEUE_CONCURRENCY').default(1).asIntPositive(), // TODO: hmmmmmmmmm | ||
}) | ||
async transcode(job: Job<PrintOptions>): Promise<JobReturnValue> { | ||
this.logger.log(`Process job ${job.id}`); | ||
|
||
const printService = this.printServiceFactory.create(job.data.outputType); | ||
|
||
const data = await printService.print( | ||
job.data.input, | ||
job.data.additionalScripts, | ||
job.data.timeout, | ||
job.data.injectPolyfill, | ||
job.data.httpHeaders, | ||
async (step: PrintStep) => await job.progress(step.toString()), | ||
); | ||
|
||
return { data, outputType: job.data.outputType }; | ||
} | ||
|
||
@OnQueueCompleted({ name: 'print' }) | ||
completedHandler(job: Job) { | ||
this.logger.log(`Finished print ${job.id}`); | ||
|
||
this.processHandler(job); | ||
} | ||
|
||
@OnQueueFailed({ name: 'print' }) | ||
failedHandler(job: Job, e: Error) { | ||
this.logger.error(`Failed print ${job.id}`, e); | ||
|
||
this.processHandler(job); | ||
} | ||
|
||
private processHandler(job: Job) { | ||
if (job.data.callbackUrl) { | ||
this.logger.log(`Addin callback job for print job ${job.id}`); | ||
|
||
this.callbackerQueue.add('callback', job.id); | ||
} | ||
} | ||
} |
Oops, something went wrong.