Created
February 11, 2021 16:02
-
-
Save urbanisierung/dc48a110f446f4e91479d473cac823a0 to your computer and use it in GitHub Desktop.
websiteshot.worker.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
export class WebsiteshotWorker { | |
constructor(private zeebeController: ZeebeController) {} | |
public create() { | |
this.zeebeController.getZeebeClient().createWorker({ | |
taskType: Worker.WEBSITESHOT_CREATE_JOB, | |
taskHandler: async (job: any, complete: any, worker: any) => { | |
const templateId = job.customHeaders.templateid; | |
if (!templateId) { | |
complete.failure('Template Id not set as header <templateid>'); | |
return; | |
} | |
logger.info(`Creating Screenshot Job for Template Id ${templateId}`); | |
const screenshotController = new ScreenshotController({ | |
projectId: ConfigController.get( | |
ConfigParameter.WEBSITESHOT_PROJECT_ID | |
), | |
apikey: ConfigController.get(ConfigParameter.WEBSITESHOT_API_KEY), | |
}); | |
try { | |
const response = await screenshotController.create(templateId); | |
complete.success({ jobId: response.jobId }); | |
} catch (error) { | |
logger.error(error); | |
complete.failure('Failed to create screenshot job via websiteshot'); | |
} | |
}, | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment