diff options
Diffstat (limited to 'packages')
-rw-r--r-- | packages/peertube-runner/README.md | 22 | ||||
-rw-r--r-- | packages/peertube-runner/peertube-runner.ts | 8 | ||||
-rw-r--r-- | packages/peertube-runner/server/process/shared/process-live.ts | 10 | ||||
-rw-r--r-- | packages/peertube-runner/server/server.ts | 17 | ||||
-rw-r--r-- | packages/peertube-runner/shared/http.ts | 2 | ||||
-rw-r--r-- | packages/peertube-runner/shared/ipc/ipc-server.ts | 4 |
6 files changed, 48 insertions, 15 deletions
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 @@ | |||
1 | # PeerTube runner | 1 | # PeerTube runner |
2 | |||
3 | Runner program to execute jobs (transcoding...) of remote PeerTube instances. | ||
4 | |||
5 | Commands below has to be run at the root of PeerTube git repository. | ||
6 | |||
7 | ## Develop | ||
8 | |||
9 | ```bash | ||
10 | npm run dev:peertube-runner | ||
11 | ``` | ||
12 | |||
13 | ## Build | ||
14 | |||
15 | ```bash | ||
16 | npm run build:peertube-runner | ||
17 | ``` | ||
18 | |||
19 | ## Run | ||
20 | |||
21 | ```bash | ||
22 | node packages/peertube-runner/dist/peertube-runner.js --help | ||
23 | ``` | ||
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') | |||
26 | try { | 26 | try { |
27 | await RunnerServer.Instance.run() | 27 | await RunnerServer.Instance.run() |
28 | } catch (err) { | 28 | } catch (err) { |
29 | console.error('Cannot run PeerTube runner as server mode', err) | 29 | logger.error('Cannot run PeerTube runner as server mode', err) |
30 | process.exit(-1) | 30 | process.exit(-1) |
31 | } | 31 | } |
32 | }) | 32 | }) |
@@ -41,7 +41,7 @@ program.command('register') | |||
41 | try { | 41 | try { |
42 | await registerRunner(options) | 42 | await registerRunner(options) |
43 | } catch (err) { | 43 | } catch (err) { |
44 | console.error('Cannot register this PeerTube runner.', err) | 44 | logger.error('Cannot register this PeerTube runner.', err) |
45 | process.exit(-1) | 45 | process.exit(-1) |
46 | } | 46 | } |
47 | }) | 47 | }) |
@@ -53,7 +53,7 @@ program.command('unregister') | |||
53 | try { | 53 | try { |
54 | await unregisterRunner(options) | 54 | await unregisterRunner(options) |
55 | } catch (err) { | 55 | } catch (err) { |
56 | console.error('Cannot unregister this PeerTube runner.', err) | 56 | logger.error('Cannot unregister this PeerTube runner.', err) |
57 | process.exit(-1) | 57 | process.exit(-1) |
58 | } | 58 | } |
59 | }) | 59 | }) |
@@ -64,7 +64,7 @@ program.command('list-registered') | |||
64 | try { | 64 | try { |
65 | await listRegistered() | 65 | await listRegistered() |
66 | } catch (err) { | 66 | } catch (err) { |
67 | console.error('Cannot list registered PeerTube instances.', err) | 67 | logger.error('Cannot list registered PeerTube instances.', err) |
68 | process.exit(-1) | 68 | process.exit(-1) |
69 | } | 69 | } |
70 | }) | 70 | }) |
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 { | |||
204 | 204 | ||
205 | // --------------------------------------------------------------------------- | 205 | // --------------------------------------------------------------------------- |
206 | 206 | ||
207 | private sendDeletedChunkUpdate (deletedChunk: string) { | 207 | private sendDeletedChunkUpdate (deletedChunk: string): Promise<any> { |
208 | if (this.ended) return | 208 | if (this.ended) return Promise.resolve() |
209 | 209 | ||
210 | logger.debug(`Sending removed live chunk ${deletedChunk} update`) | 210 | logger.debug(`Sending removed live chunk ${deletedChunk} update`) |
211 | 211 | ||
@@ -230,8 +230,8 @@ export class ProcessLiveRTMPHLSTranscoding { | |||
230 | return this.updateWithRetry(payload) | 230 | return this.updateWithRetry(payload) |
231 | } | 231 | } |
232 | 232 | ||
233 | private sendAddedChunkUpdate (addedChunk: string) { | 233 | private sendAddedChunkUpdate (addedChunk: string): Promise<any> { |
234 | if (this.ended) return | 234 | if (this.ended) return Promise.resolve() |
235 | 235 | ||
236 | logger.debug(`Sending added live chunk ${addedChunk} update`) | 236 | logger.debug(`Sending added live chunk ${addedChunk} update`) |
237 | 237 | ||
@@ -257,7 +257,7 @@ export class ProcessLiveRTMPHLSTranscoding { | |||
257 | return this.updateWithRetry(payload) | 257 | return this.updateWithRetry(payload) |
258 | } | 258 | } |
259 | 259 | ||
260 | private async updateWithRetry (payload: LiveRTMPHLSTranscodingUpdatePayload, currentTry = 1) { | 260 | private async updateWithRetry (payload: LiveRTMPHLSTranscodingUpdatePayload, currentTry = 1): Promise<any> { |
261 | if (this.ended || this.errored) return | 261 | if (this.ended || this.errored) return |
262 | 262 | ||
263 | try { | 263 | 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 { | |||
23 | 23 | ||
24 | private checkingAvailableJobs = false | 24 | private checkingAvailableJobs = false |
25 | 25 | ||
26 | private cleaningUp = false | ||
27 | |||
26 | private readonly sockets = new Map<PeerTubeServer, Socket>() | 28 | private readonly sockets = new Map<PeerTubeServer, Socket>() |
27 | 29 | ||
28 | private constructor () {} | 30 | private constructor () {} |
@@ -45,13 +47,17 @@ export class RunnerServer { | |||
45 | try { | 47 | try { |
46 | await ipcServer.run(this) | 48 | await ipcServer.run(this) |
47 | } catch (err) { | 49 | } catch (err) { |
48 | console.error('Cannot start local socket for IPC communication', err) | 50 | logger.error('Cannot start local socket for IPC communication', err) |
49 | process.exit(-1) | 51 | process.exit(-1) |
50 | } | 52 | } |
51 | 53 | ||
52 | // Cleanup on exit | 54 | // Cleanup on exit |
53 | for (const code of [ 'SIGINT', 'SIGUSR1', 'SIGUSR2', 'uncaughtException' ]) { | 55 | for (const code of [ 'SIGINT', 'SIGUSR1', 'SIGUSR2', 'uncaughtException' ]) { |
54 | process.on(code, async () => { | 56 | process.on(code, async (err, origin) => { |
57 | if (code === 'uncaughtException') { | ||
58 | logger.error({ err, origin }, 'uncaughtException') | ||
59 | } | ||
60 | |||
55 | await this.onExit() | 61 | await this.onExit() |
56 | }) | 62 | }) |
57 | } | 63 | } |
@@ -244,6 +250,11 @@ export class RunnerServer { | |||
244 | } | 250 | } |
245 | 251 | ||
246 | private async onExit () { | 252 | private async onExit () { |
253 | if (this.cleaningUp) return | ||
254 | this.cleaningUp = true | ||
255 | |||
256 | logger.info('Cleaning up after program exit') | ||
257 | |||
247 | try { | 258 | try { |
248 | for (const { server, job } of this.processingJobs) { | 259 | for (const { server, job } of this.processingJobs) { |
249 | await server.runnerJobs.abort({ | 260 | await server.runnerJobs.abort({ |
@@ -256,7 +267,7 @@ export class RunnerServer { | |||
256 | 267 | ||
257 | await this.cleanupTMP() | 268 | await this.cleanupTMP() |
258 | } catch (err) { | 269 | } catch (err) { |
259 | console.error(err) | 270 | logger.error(err) |
260 | process.exit(-1) | 271 | process.exit(-1) |
261 | } | 272 | } |
262 | 273 | ||
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: { | |||
47 | 47 | ||
48 | request.on('error', err => { | 48 | request.on('error', err => { |
49 | remove(destination) | 49 | remove(destination) |
50 | .catch(err => console.error(err)) | 50 | .catch(err => logger.error(err)) |
51 | 51 | ||
52 | return rej(err) | 52 | return rej(err) |
53 | }) | 53 | }) |
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 { | |||
27 | 27 | ||
28 | this.sendReponse(res, { success: true, data }) | 28 | this.sendReponse(res, { success: true, data }) |
29 | } catch (err) { | 29 | } catch (err) { |
30 | console.error('Cannot execute RPC call', err) | 30 | logger.error('Cannot execute RPC call', err) |
31 | this.sendReponse(res, { success: false, error: err.message }) | 31 | this.sendReponse(res, { success: false, error: err.message }) |
32 | } | 32 | } |
33 | }) | 33 | }) |
@@ -56,6 +56,6 @@ export class IPCServer { | |||
56 | body: IPCReponse<T> | 56 | body: IPCReponse<T> |
57 | ) { | 57 | ) { |
58 | response(body) | 58 | response(body) |
59 | .catch(err => console.error('Cannot send response after IPC request', err)) | 59 | .catch(err => logger.error('Cannot send response after IPC request', err)) |
60 | } | 60 | } |
61 | } | 61 | } |