From 0c9668f77901e7540e2c7045eb0f2974a4842a69 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 21 Apr 2023 14:55:10 +0200 Subject: Implement remote runner jobs in server Move ffmpeg functions to @shared --- server/lib/runners/runner.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 server/lib/runners/runner.ts (limited to 'server/lib/runners/runner.ts') diff --git a/server/lib/runners/runner.ts b/server/lib/runners/runner.ts new file mode 100644 index 000000000..74c814ba1 --- /dev/null +++ b/server/lib/runners/runner.ts @@ -0,0 +1,36 @@ +import express from 'express' +import { retryTransactionWrapper } from '@server/helpers/database-utils' +import { logger, loggerTagsFactory } from '@server/helpers/logger' +import { sequelizeTypescript } from '@server/initializers/database' +import { MRunner } from '@server/types/models/runners' + +const lTags = loggerTagsFactory('runner') + +const updatingRunner = new Set() + +function updateLastRunnerContact (req: express.Request, runner: MRunner) { + const now = new Date() + + // Don't update last runner contact too often + if (now.getTime() - runner.lastContact.getTime() < 2000) return + if (updatingRunner.has(runner.id)) return + + updatingRunner.add(runner.id) + + runner.lastContact = now + runner.ip = req.ip + + logger.debug('Updating last runner contact for %s', runner.name, lTags(runner.name)) + + retryTransactionWrapper(() => { + return sequelizeTypescript.transaction(async transaction => { + return runner.save({ transaction }) + }) + }) + .catch(err => logger.error('Cannot update last runner contact for %s', runner.name, { err, ...lTags(runner.name) })) + .finally(() => updatingRunner.delete(runner.id)) +} + +export { + updateLastRunnerContact +} -- cgit v1.2.3