(message: QpeWorkerStartMessage)
| 78 | } |
| 79 | |
| 80 | async function handleStart(message: QpeWorkerStartMessage): Promise<QpeWorkerReadyResponse> { |
| 81 | // It should only be imported after initializing OpenTelemetry |
| 82 | const { Server, parseSize, parseDuration } = await import('@prisma/query-plan-executor') |
| 83 | |
| 84 | const qpe = await Server.create({ |
| 85 | databaseUrl: message.databaseUrl, |
| 86 | maxResponseSize: parseSize('128 MiB'), |
| 87 | queryTimeout: parseDuration('PT30S'), |
| 88 | maxTransactionTimeout: parseDuration('PT1M'), |
| 89 | maxTransactionWaitTime: parseDuration('PT1M'), |
| 90 | perRequestLogContext: { |
| 91 | logFormat: 'text', |
| 92 | logLevel: 'warn', |
| 93 | }, |
| 94 | }) |
| 95 | |
| 96 | const hostname = '127.0.0.1' |
| 97 | |
| 98 | const net = serve({ |
| 99 | fetch: qpe.fetch, |
| 100 | hostname, |
| 101 | port: 0, |
| 102 | }) |
| 103 | |
| 104 | await events.once(net, 'listening') |
| 105 | const address = net.address() |
| 106 | |
| 107 | if (address === null) { |
| 108 | throw new Error('query plan executor server did not start') |
| 109 | } |
| 110 | |
| 111 | if (typeof address === 'string') { |
| 112 | throw new Error('query plan executor must be listening on TCP and not Unix socket') |
| 113 | } |
| 114 | |
| 115 | server = { qpe, net } |
| 116 | |
| 117 | return { type: 'ready', hostname, port: address.port } |
| 118 | } |
| 119 | |
| 120 | async function handleShutdown(): Promise<QpeWorkerShutdownResponse> { |
| 121 | if (server) { |
no test coverage detected