From 3a0c2a77b1a6626699514ddaf8135f4397175443 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 2 May 2023 13:51:06 +0200 Subject: Enable external plugins to test the PR --- packages/peertube-runner/README.md | 22 ++++++++++++++++++++++ packages/peertube-runner/peertube-runner.ts | 8 ++++---- .../server/process/shared/process-live.ts | 10 +++++----- packages/peertube-runner/server/server.ts | 17 ++++++++++++++--- packages/peertube-runner/shared/http.ts | 2 +- packages/peertube-runner/shared/ipc/ipc-server.ts | 4 ++-- 6 files changed, 48 insertions(+), 15 deletions(-) (limited to 'packages/peertube-runner') diff --git a/packages/peertube-runner/README.md b/packages/peertube-runner/README.md index b7cf174d5..87c3c5354 100644 --- a/packages/peertube-runner/README.md +++ b/packages/peertube-runner/README.md @@ -1 +1,23 @@ # PeerTube runner + +Runner program to execute jobs (transcoding...) of remote PeerTube instances. + +Commands below has to be run at the root of PeerTube git repository. + +## Develop + +```bash +npm run dev:peertube-runner +``` + +## Build + +```bash +npm run build:peertube-runner +``` + +## Run + +```bash +node packages/peertube-runner/dist/peertube-runner.js --help +``` diff --git a/packages/peertube-runner/peertube-runner.ts b/packages/peertube-runner/peertube-runner.ts index 6bfd9ac0f..f02526ef9 100644 --- a/packages/peertube-runner/peertube-runner.ts +++ b/packages/peertube-runner/peertube-runner.ts @@ -26,7 +26,7 @@ program.command('server') try { await RunnerServer.Instance.run() } catch (err) { - console.error('Cannot run PeerTube runner as server mode', err) + logger.error('Cannot run PeerTube runner as server mode', err) process.exit(-1) } }) @@ -41,7 +41,7 @@ program.command('register') try { await registerRunner(options) } catch (err) { - console.error('Cannot register this PeerTube runner.', err) + logger.error('Cannot register this PeerTube runner.', err) process.exit(-1) } }) @@ -53,7 +53,7 @@ program.command('unregister') try { await unregisterRunner(options) } catch (err) { - console.error('Cannot unregister this PeerTube runner.', err) + logger.error('Cannot unregister this PeerTube runner.', err) process.exit(-1) } }) @@ -64,7 +64,7 @@ program.command('list-registered') try { await listRegistered() } catch (err) { - console.error('Cannot list registered PeerTube instances.', err) + logger.error('Cannot list registered PeerTube instances.', err) process.exit(-1) } }) diff --git a/packages/peertube-runner/server/process/shared/process-live.ts b/packages/peertube-runner/server/process/shared/process-live.ts index 5a3b596a2..b17b51c7c 100644 --- a/packages/peertube-runner/server/process/shared/process-live.ts +++ b/packages/peertube-runner/server/process/shared/process-live.ts @@ -204,8 +204,8 @@ export class ProcessLiveRTMPHLSTranscoding { // --------------------------------------------------------------------------- - private sendDeletedChunkUpdate (deletedChunk: string) { - if (this.ended) return + private sendDeletedChunkUpdate (deletedChunk: string): Promise { + if (this.ended) return Promise.resolve() logger.debug(`Sending removed live chunk ${deletedChunk} update`) @@ -230,8 +230,8 @@ export class ProcessLiveRTMPHLSTranscoding { return this.updateWithRetry(payload) } - private sendAddedChunkUpdate (addedChunk: string) { - if (this.ended) return + private sendAddedChunkUpdate (addedChunk: string): Promise { + if (this.ended) return Promise.resolve() logger.debug(`Sending added live chunk ${addedChunk} update`) @@ -257,7 +257,7 @@ export class ProcessLiveRTMPHLSTranscoding { return this.updateWithRetry(payload) } - private async updateWithRetry (payload: LiveRTMPHLSTranscodingUpdatePayload, currentTry = 1) { + private async updateWithRetry (payload: LiveRTMPHLSTranscodingUpdatePayload, currentTry = 1): Promise { if (this.ended || this.errored) return try { diff --git a/packages/peertube-runner/server/server.ts b/packages/peertube-runner/server/server.ts index 724f359bd..e851dfc7c 100644 --- a/packages/peertube-runner/server/server.ts +++ b/packages/peertube-runner/server/server.ts @@ -23,6 +23,8 @@ export class RunnerServer { private checkingAvailableJobs = false + private cleaningUp = false + private readonly sockets = new Map() private constructor () {} @@ -45,13 +47,17 @@ export class RunnerServer { try { await ipcServer.run(this) } catch (err) { - console.error('Cannot start local socket for IPC communication', err) + logger.error('Cannot start local socket for IPC communication', err) process.exit(-1) } // Cleanup on exit for (const code of [ 'SIGINT', 'SIGUSR1', 'SIGUSR2', 'uncaughtException' ]) { - process.on(code, async () => { + process.on(code, async (err, origin) => { + if (code === 'uncaughtException') { + logger.error({ err, origin }, 'uncaughtException') + } + await this.onExit() }) } @@ -244,6 +250,11 @@ export class RunnerServer { } private async onExit () { + if (this.cleaningUp) return + this.cleaningUp = true + + logger.info('Cleaning up after program exit') + try { for (const { server, job } of this.processingJobs) { await server.runnerJobs.abort({ @@ -256,7 +267,7 @@ export class RunnerServer { await this.cleanupTMP() } catch (err) { - console.error(err) + logger.error(err) process.exit(-1) } diff --git a/packages/peertube-runner/shared/http.ts b/packages/peertube-runner/shared/http.ts index d3fff70d1..df64dc168 100644 --- a/packages/peertube-runner/shared/http.ts +++ b/packages/peertube-runner/shared/http.ts @@ -47,7 +47,7 @@ export function downloadFile (options: { request.on('error', err => { remove(destination) - .catch(err => console.error(err)) + .catch(err => logger.error(err)) return rej(err) }) diff --git a/packages/peertube-runner/shared/ipc/ipc-server.ts b/packages/peertube-runner/shared/ipc/ipc-server.ts index bc340198b..922dc93e5 100644 --- a/packages/peertube-runner/shared/ipc/ipc-server.ts +++ b/packages/peertube-runner/shared/ipc/ipc-server.ts @@ -27,7 +27,7 @@ export class IPCServer { this.sendReponse(res, { success: true, data }) } catch (err) { - console.error('Cannot execute RPC call', err) + logger.error('Cannot execute RPC call', err) this.sendReponse(res, { success: false, error: err.message }) } }) @@ -56,6 +56,6 @@ export class IPCServer { body: IPCReponse ) { response(body) - .catch(err => console.error('Cannot send response after IPC request', err)) + .catch(err => logger.error('Cannot send response after IPC request', err)) } } -- cgit v1.2.3