From f474a519dc08df47c96ead9e0216912582def4f7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 26 May 2023 09:03:50 +0200 Subject: Specify runner name when unregistering the runner --- packages/peertube-runner/peertube-runner.ts | 1 + packages/peertube-runner/register/register.ts | 1 + packages/peertube-runner/server/server.ts | 15 ++++++++------- packages/peertube-runner/shared/ipc/ipc-client.ts | 1 + packages/peertube-runner/shared/ipc/ipc-server.ts | 2 +- .../shared/ipc/shared/ipc-request.model.ts | 2 +- server/tests/peertube-runner/client-cli.ts | 2 +- server/tests/peertube-runner/live-transcoding.ts | 2 +- server/tests/peertube-runner/studio-transcoding.ts | 2 +- server/tests/peertube-runner/vod-transcoding.ts | 2 +- server/tests/shared/peertube-runner-process.ts | 8 ++++++-- support/doc/tools.md | 2 +- 12 files changed, 24 insertions(+), 16 deletions(-) diff --git a/packages/peertube-runner/peertube-runner.ts b/packages/peertube-runner/peertube-runner.ts index 858d85e6a..32586c4d9 100644 --- a/packages/peertube-runner/peertube-runner.ts +++ b/packages/peertube-runner/peertube-runner.ts @@ -55,6 +55,7 @@ program.command('register') program.command('unregister') .description('Unregister the runner from PeerTube instance') .requiredOption('--url ', 'PeerTube instance URL', parseUrl) + .requiredOption('--runner-name ', 'Runner name') .action(async options => { try { await unregisterRunner(options) diff --git a/packages/peertube-runner/register/register.ts b/packages/peertube-runner/register/register.ts index a69390933..ca1bf0f5a 100644 --- a/packages/peertube-runner/register/register.ts +++ b/packages/peertube-runner/register/register.ts @@ -16,6 +16,7 @@ export async function registerRunner (options: { export async function unregisterRunner (options: { url: string + runnerName: string }) { const client = new IPCClient() await client.run() diff --git a/packages/peertube-runner/server/server.ts b/packages/peertube-runner/server/server.ts index 087405dfe..e76131c74 100644 --- a/packages/peertube-runner/server/server.ts +++ b/packages/peertube-runner/server/server.ts @@ -121,27 +121,28 @@ export class RunnerServer { async unregisterRunner (options: { url: string + runnerName: string }) { - const { url } = options + const { url, runnerName } = options - const server = this.servers.find(s => s.url === url) + const server = this.servers.find(s => s.url === url && s.runnerName === runnerName) if (!server) { - logger.error(`Unknown server ${url} to unregister`) + logger.error(`Unknown server ${url} - ${runnerName} to unregister`) return } - logger.info(`Unregistering runner ${server.runnerName} on ${url}...`) + logger.info(`Unregistering runner ${runnerName} on ${url}...`) try { await server.runners.unregister({ runnerToken: server.runnerToken }) } catch (err) { - logger.error({ err }, `Cannot unregister runner ${server.runnerName} on ${url}`) + logger.error({ err }, `Cannot unregister runner ${runnerName} on ${url}`) } this.unloadServer(server) await this.saveRegisteredInstancesInConf() - logger.info(`Unregistered runner ${server.runnerName} on ${server.url}`) + logger.info(`Unregistered runner ${runnerName} on ${url}`) } private unloadServer (server: PeerTubeServer) { @@ -195,7 +196,7 @@ export class RunnerServer { if (code === ServerErrorCode.UNKNOWN_RUNNER_TOKEN) { logger.error({ err }, `Unregistering ${server.url} as the runner token ${server.runnerToken} is invalid`) - await this.unregisterRunner({ url: server.url }) + await this.unregisterRunner({ url: server.url, runnerName: server.runnerName }) return } diff --git a/packages/peertube-runner/shared/ipc/ipc-client.ts b/packages/peertube-runner/shared/ipc/ipc-client.ts index db8d7f1bf..f8e72f97f 100644 --- a/packages/peertube-runner/shared/ipc/ipc-client.ts +++ b/packages/peertube-runner/shared/ipc/ipc-client.ts @@ -47,6 +47,7 @@ export class IPCClient { async askUnregister (options: { url: string + runnerName: string }) { const req: IPCRequest = { type: 'unregister', diff --git a/packages/peertube-runner/shared/ipc/ipc-server.ts b/packages/peertube-runner/shared/ipc/ipc-server.ts index 922dc93e5..4b67d01ae 100644 --- a/packages/peertube-runner/shared/ipc/ipc-server.ts +++ b/packages/peertube-runner/shared/ipc/ipc-server.ts @@ -40,7 +40,7 @@ export class IPCServer { return undefined case 'unregister': - await this.runnerServer.unregisterRunner({ url: req.url }) + await this.runnerServer.unregisterRunner(pick(req, [ 'url', 'runnerName' ])) return undefined case 'list-registered': diff --git a/packages/peertube-runner/shared/ipc/shared/ipc-request.model.ts b/packages/peertube-runner/shared/ipc/shared/ipc-request.model.ts index 0f733cdfe..352808c74 100644 --- a/packages/peertube-runner/shared/ipc/shared/ipc-request.model.ts +++ b/packages/peertube-runner/shared/ipc/shared/ipc-request.model.ts @@ -11,5 +11,5 @@ export type IPCRequestRegister = { runnerDescription?: string } -export type IPCRequestUnregister = { type: 'unregister', url: string } +export type IPCRequestUnregister = { type: 'unregister', url: string, runnerName: string } export type IPCRequestListRegistered = { type: 'list-registered' } diff --git a/server/tests/peertube-runner/client-cli.ts b/server/tests/peertube-runner/client-cli.ts index cc8136c4a..5cbdc4e77 100644 --- a/server/tests/peertube-runner/client-cli.ts +++ b/server/tests/peertube-runner/client-cli.ts @@ -53,7 +53,7 @@ describe('Test peertube-runner program client CLI', function () { }) it('Should unregister the PeerTube instance', async function () { - await peertubeRunner.unregisterPeerTubeInstance() + await peertubeRunner.unregisterPeerTubeInstance({ runnerName: 'my super runner' }) }) it('Should not have PeerTube instance listed', async function () { diff --git a/server/tests/peertube-runner/live-transcoding.ts b/server/tests/peertube-runner/live-transcoding.ts index c2ca1de96..4826c61f7 100644 --- a/server/tests/peertube-runner/live-transcoding.ts +++ b/server/tests/peertube-runner/live-transcoding.ts @@ -190,7 +190,7 @@ describe('Test Live transcoding in peertube-runner program', function () { after(async function () { if (peertubeRunner) { - await peertubeRunner.unregisterPeerTubeInstance() + await peertubeRunner.unregisterPeerTubeInstance({ runnerName: 'runner' }) peertubeRunner.kill() } diff --git a/server/tests/peertube-runner/studio-transcoding.ts b/server/tests/peertube-runner/studio-transcoding.ts index 69b38a536..988201947 100644 --- a/server/tests/peertube-runner/studio-transcoding.ts +++ b/server/tests/peertube-runner/studio-transcoding.ts @@ -115,7 +115,7 @@ describe('Test studio transcoding in peertube-runner program', function () { after(async function () { if (peertubeRunner) { - await peertubeRunner.unregisterPeerTubeInstance() + await peertubeRunner.unregisterPeerTubeInstance({ runnerName: 'runner' }) peertubeRunner.kill() } diff --git a/server/tests/peertube-runner/vod-transcoding.ts b/server/tests/peertube-runner/vod-transcoding.ts index aefec394d..c3f41c097 100644 --- a/server/tests/peertube-runner/vod-transcoding.ts +++ b/server/tests/peertube-runner/vod-transcoding.ts @@ -341,7 +341,7 @@ describe('Test VOD transcoding in peertube-runner program', function () { after(async function () { if (peertubeRunner) { - await peertubeRunner.unregisterPeerTubeInstance() + await peertubeRunner.unregisterPeerTubeInstance({ runnerName: 'runner' }) peertubeRunner.kill() } diff --git a/server/tests/shared/peertube-runner-process.ts b/server/tests/shared/peertube-runner-process.ts index b3c8dfe0e..9304ebcc8 100644 --- a/server/tests/shared/peertube-runner-process.ts +++ b/server/tests/shared/peertube-runner-process.ts @@ -60,8 +60,12 @@ export class PeerTubeRunnerProcess { return execa.node(this.getRunnerPath(), args) } - unregisterPeerTubeInstance () { - const args = [ 'unregister', '--url', this.server.url, ...this.buildIdArg() ] + unregisterPeerTubeInstance (options: { + runnerName: string + }) { + const { runnerName } = options + + const args = [ 'unregister', '--url', this.server.url, '--runner-name', runnerName, ...this.buildIdArg() ] return execa.node(this.getRunnerPath(), args) } diff --git a/support/doc/tools.md b/support/doc/tools.md index c12b00e32..f45a39718 100644 --- a/support/doc/tools.md +++ b/support/doc/tools.md @@ -398,7 +398,7 @@ The runner will then use a websocket connection with the PeerTube instance to be To unregister a PeerTube instance: ```bash -peertube-runner unregister --url http://peertube.example.com +peertube-runner unregister --url http://peertube.example.com --runner-name my-runner-name ``` ### List registered instances -- cgit v1.2.3