feat(preview-service): add load and render duration calculation to preview service
This commit is contained in:
@@ -82,11 +82,18 @@ const pageFunction = async ({
|
||||
logger.error({ err }, 'Page crashed')
|
||||
throw err
|
||||
})
|
||||
const start = new Date().getTime()
|
||||
await page.goto(`http://127.0.0.1:${port}/index.html`)
|
||||
page.setDefaultTimeout(timeout)
|
||||
const previewResult = await page.evaluate(async (job: JobPayload) => {
|
||||
const loadDone = new Date().getTime()
|
||||
const loadDurationSeconds = loadDone - start
|
||||
// measure here before load
|
||||
await window.load(job)
|
||||
return await window.takeScreenshot()
|
||||
const renderDurationSeconds = new Date().getTime() - loadDone
|
||||
// measure here
|
||||
const renderResult = await window.takeScreenshot()
|
||||
return { ...renderResult, loadDurationSeconds, renderDurationSeconds }
|
||||
}, job)
|
||||
|
||||
return { jobId: job.jobId, status: 'success', result: previewResult }
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { PreviewResult } from './job.js'
|
||||
import { PreviewPageResult } from './job.js'
|
||||
|
||||
export interface PreviewGenerator {
|
||||
takeScreenshot: TakeScreenshot
|
||||
load: Load
|
||||
}
|
||||
|
||||
export type TakeScreenshot = () => Promise<PreviewResult>
|
||||
export type TakeScreenshot = () => Promise<PreviewPageResult>
|
||||
|
||||
export type LoadArgs = { url: string; token: string }
|
||||
export type Load = (args: LoadArgs) => Promise<void>
|
||||
|
||||
export type { PreviewResult } from './job.js'
|
||||
export type { PreviewPageResult } from './job.js'
|
||||
|
||||
@@ -13,17 +13,27 @@ export const jobPayload = job.merge(
|
||||
)
|
||||
export type JobPayload = z.infer<typeof jobPayload>
|
||||
|
||||
const previewResult = z.object({
|
||||
const previewPageResult = z.object({
|
||||
durationSeconds: z.number().describe('Duration to generate the preview, in seconds'),
|
||||
screenshots: z.record(z.string(), z.string())
|
||||
})
|
||||
|
||||
export type PreviewResult = z.infer<typeof previewResult>
|
||||
const previewJobResult = previewPageResult.extend({
|
||||
loadDurationSeconds: z
|
||||
.number()
|
||||
.describe('Duration to load the object from the server in seconds'),
|
||||
renderDurationSeconds: z
|
||||
.number()
|
||||
.describe('Duration to render the preview images in seconds')
|
||||
})
|
||||
|
||||
export type PreviewPageResult = z.infer<typeof previewPageResult>
|
||||
export type PreviewJobResult = z.infer<typeof previewJobResult>
|
||||
|
||||
const previewSuccessPayload = job.merge(
|
||||
z.object({
|
||||
status: z.literal('success'),
|
||||
result: previewResult
|
||||
result: previewJobResult
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user