Skip to content

Commit

Permalink
Check available jobs on reconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobozzz committed Mar 8, 2024
1 parent 36710e5 commit 54a7183
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
7 changes: 7 additions & 0 deletions apps/peertube-runner/scripts/watch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as esbuild from 'esbuild'
import { esbuildOptions } from './build.js'

const context = await esbuild.context(esbuildOptions)

// Enable watch mode
await context.watch()
20 changes: 16 additions & 4 deletions apps/peertube-runner/src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class RunnerServer {
private checkingAvailableJobs = false

private cleaningUp = false
private initialized = false

private readonly sockets = new Map<PeerTubeServer, Socket>()

Expand Down Expand Up @@ -70,6 +71,7 @@ export class RunnerServer {

logger.info(`Using ${ConfigManager.Instance.getTranscodingDirectory()} for transcoding directory`)

this.initialized = true
await this.checkAvailableJobs()
}

Expand Down Expand Up @@ -98,8 +100,6 @@ export class RunnerServer {
await this.saveRegisteredInstancesInConf()

logger.info(`Registered runner ${runnerName} on ${url}`)

await this.checkAvailableJobs()
}

private loadServer (server: PeerTubeServer) {
Expand All @@ -114,8 +114,14 @@ export class RunnerServer {
})

socket.on('connect_error', err => logger.warn({ err }, `Cannot connect to ${url} socket`))
socket.on('connect', () => logger.info(`Connected to ${url} socket`))
socket.on('available-jobs', () => this.checkAvailableJobs())
socket.on('available-jobs', () => this.safeAsyncCheckAvailableJobs())

socket.on('connect', () => {
logger.info(`Connected to ${url} socket`)

this.safeAsyncCheckAvailableJobs()
})
socket.on('disconnect', () => logger.warn(`Disconnected from ${url} socket`))

this.sockets.set(server, socket)
}
Expand Down Expand Up @@ -169,7 +175,13 @@ export class RunnerServer {

// ---------------------------------------------------------------------------

private safeAsyncCheckAvailableJobs () {
this.checkAvailableJobs()
.catch(err => logger.error({ err }, `Cannot check available jobs`))
}

private async checkAvailableJobs () {
if (!this.initialized) return
if (this.checkingAvailableJobs) return

this.checkingAvailableJobs = true
Expand Down

0 comments on commit 54a7183

Please sign in to comment.