-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_stall.ts
More file actions
43 lines (40 loc) · 1.27 KB
/
test_stall.ts
File metadata and controls
43 lines (40 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { BaseCommand } from '@adonisjs/core/ace'
import { connect } from 'node:net'
import { subProcessLogger as logger } from '#services/logger'
import type { CommandOptions } from '@adonisjs/core/types/ace'
import type { Socket } from 'node:net'
export default class TestStall extends BaseCommand {
static commandName = 'test:stall'
static description = 'Test how camera feeds handle stalls'
static options: CommandOptions = {}
async run() {
this.logger.info('Sending command via IPC')
const payload = JSON.stringify(['test:stall', {}])
const ipcSocketPath = this.app.makePath('resources/ipc.sock')
let client: Socket
try {
await new Promise<void>((resolve, reject) => {
client = connect(ipcSocketPath, () => {
client.off('error', reject)
resolve()
})
client.on('error', reject)
})
} catch (err) {
logger.error(err)
process.exit(1)
}
client!.on('error', (err) => {
logger.error(err)
process.exit(1)
})
client!.write(payload)
await new Promise<void>((resolve) => setTimeout(resolve, 250))
const closePromise = new Promise<void>((resolve) => {
client!.on('close', () => resolve())
})
client!.end()
await closePromise
process.exit(0)
}
}