You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
737 B
24 lines
737 B
import { Process, Processor } from '@nestjs/bull';
|
|
import { Injectable } from '@nestjs/common';
|
|
import { ScreenshotterService } from './screenshotter.service';
|
|
import { QUEUE_NAME, ScreenshotJob } from './shared';
|
|
|
|
@Injectable()
|
|
@Processor(QUEUE_NAME)
|
|
export class ScreenshotsProcessor {
|
|
constructor(private readonly screenshotterService: ScreenshotterService) {}
|
|
|
|
@Process()
|
|
async handleScreenshotJob(job: ScreenshotJob) {
|
|
try {
|
|
const imageData = await this.screenshotterService.takeScreenshot({
|
|
url: job.data.pageUrl,
|
|
imageType: job.data.imageType,
|
|
})
|
|
|
|
job.moveToCompleted(imageData.toString('base64'))
|
|
} catch(err) {
|
|
job.moveToFailed({ message: JSON.stringify(err) })
|
|
}
|
|
}
|
|
}
|
|
|