Better runner error UX when server is not run

This commit is contained in:
Chocobozzz 2023-05-16 09:24:31 +02:00
parent 2870570505
commit 0d6a8289fb
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 23 additions and 7 deletions

View File

@ -31,7 +31,7 @@ program.command('server')
try { try {
await RunnerServer.Instance.run() await RunnerServer.Instance.run()
} catch (err) { } catch (err) {
logger.error('Cannot run PeerTube runner as server mode', err) logger.error(err, 'Cannot run PeerTube runner as server mode')
process.exit(-1) process.exit(-1)
} }
}) })
@ -46,7 +46,8 @@ program.command('register')
try { try {
await registerRunner(options) await registerRunner(options)
} catch (err) { } catch (err) {
logger.error('Cannot register this PeerTube runner.', err) console.error('Cannot register this PeerTube runner.')
console.error(err)
process.exit(-1) process.exit(-1)
} }
}) })
@ -58,7 +59,8 @@ program.command('unregister')
try { try {
await unregisterRunner(options) await unregisterRunner(options)
} catch (err) { } catch (err) {
logger.error('Cannot unregister this PeerTube runner.', err) console.error('Cannot unregister this PeerTube runner.')
console.error(err)
process.exit(-1) process.exit(-1)
} }
}) })
@ -69,7 +71,8 @@ program.command('list-registered')
try { try {
await listRegistered() await listRegistered()
} catch (err) { } catch (err) {
logger.error('Cannot list registered PeerTube instances.', err) console.error('Cannot list registered PeerTube instances.')
console.error(err)
process.exit(-1) process.exit(-1)
} }
}) })

View File

@ -11,8 +11,21 @@ export class IPCClient {
await ensureDir(ConfigManager.Instance.getSocketDirectory()) await ensureDir(ConfigManager.Instance.getSocketDirectory())
const socketPath = ConfigManager.Instance.getSocketPath() const socketPath = ConfigManager.Instance.getSocketPath()
this.netIPC = new NetIPC({ path: socketPath }) this.netIPC = new NetIPC({ path: socketPath })
await this.netIPC.connect()
try {
await this.netIPC.connect()
} catch (err) {
if (err.code === 'ECONNREFUSED') {
throw new Error(
'This runner is not currently running in server mode on this system. ' +
'Please run it using the `server` command first (in another terminal for example) and then retry your command.'
)
}
throw err
}
} }
async askRegister (options: { async askRegister (options: {

View File

@ -376,7 +376,7 @@ peertube-runner [commands] --id instance-3
### Run the server ### Run the server
Run the runner in server mode so it can run transcoding jobs of registered PeerTube instances: You need to run the runner in server mode first so it can run transcoding jobs of registered PeerTube instances:
```bash ```bash
peertube-runner server peertube-runner server
@ -384,7 +384,7 @@ peertube-runner server
### Register ### Register
To register the runner on a new PeerTube instance so the runner can process its transcoding job: Then, you can register the runner on a new PeerTube instance so the runner can process its transcoding job:
```bash ```bash
peertube-runner register --url http://peertube.example.com --registration-token ptrrt-... --runner-name my-runner-name peertube-runner register --url http://peertube.example.com --registration-token ptrrt-... --runner-name my-runner-name