diff options
Diffstat (limited to 'server/lib/runners/runner.ts')
-rw-r--r-- | server/lib/runners/runner.ts | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/server/lib/runners/runner.ts b/server/lib/runners/runner.ts deleted file mode 100644 index 947fdb3f0..000000000 --- a/server/lib/runners/runner.ts +++ /dev/null | |||
@@ -1,49 +0,0 @@ | |||
1 | import express from 'express' | ||
2 | import { retryTransactionWrapper } from '@server/helpers/database-utils' | ||
3 | import { logger, loggerTagsFactory } from '@server/helpers/logger' | ||
4 | import { sequelizeTypescript } from '@server/initializers/database' | ||
5 | import { MRunner, MRunnerJob } from '@server/types/models/runners' | ||
6 | import { RUNNER_JOBS } from '@server/initializers/constants' | ||
7 | import { RunnerJobState } from '@shared/models' | ||
8 | |||
9 | const lTags = loggerTagsFactory('runner') | ||
10 | |||
11 | const updatingRunner = new Set<number>() | ||
12 | |||
13 | function updateLastRunnerContact (req: express.Request, runner: MRunner) { | ||
14 | const now = new Date() | ||
15 | |||
16 | // Don't update last runner contact too often | ||
17 | if (now.getTime() - runner.lastContact.getTime() < RUNNER_JOBS.LAST_CONTACT_UPDATE_INTERVAL) return | ||
18 | if (updatingRunner.has(runner.id)) return | ||
19 | |||
20 | updatingRunner.add(runner.id) | ||
21 | |||
22 | runner.lastContact = now | ||
23 | runner.ip = req.ip | ||
24 | |||
25 | logger.debug('Updating last runner contact for %s', runner.name, lTags(runner.name)) | ||
26 | |||
27 | retryTransactionWrapper(() => { | ||
28 | return sequelizeTypescript.transaction(async transaction => { | ||
29 | return runner.save({ transaction }) | ||
30 | }) | ||
31 | }) | ||
32 | .catch(err => logger.error('Cannot update last runner contact for %s', runner.name, { err, ...lTags(runner.name) })) | ||
33 | .finally(() => updatingRunner.delete(runner.id)) | ||
34 | } | ||
35 | |||
36 | function runnerJobCanBeCancelled (runnerJob: MRunnerJob) { | ||
37 | const allowedStates = new Set<RunnerJobState>([ | ||
38 | RunnerJobState.PENDING, | ||
39 | RunnerJobState.PROCESSING, | ||
40 | RunnerJobState.WAITING_FOR_PARENT_JOB | ||
41 | ]) | ||
42 | |||
43 | return allowedStates.has(runnerJob.state) | ||
44 | } | ||
45 | |||
46 | export { | ||
47 | updateLastRunnerContact, | ||
48 | runnerJobCanBeCancelled | ||
49 | } | ||