aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-07-27 11:44:31 +0200
committerChocobozzz <me@florianbigard.com>2023-07-27 14:17:12 +0200
commitf18003d0ac5c3fc6ec8de2a89102d1e1e89182df (patch)
tree0b3baa5658478607f3417fe7c747cc3a782f15b3 /server/models
parentf5af5feb5a41eb6e2796e480402106b55bd10f04 (diff)
downloadPeerTube-f18003d0ac5c3fc6ec8de2a89102d1e1e89182df.tar.gz
PeerTube-f18003d0ac5c3fc6ec8de2a89102d1e1e89182df.tar.zst
PeerTube-f18003d0ac5c3fc6ec8de2a89102d1e1e89182df.zip
Improve runner management
* Add ability to remove runner jobs * Add runner job state quick filter * Merge registration tokens and runners tables in the same page * Add copy button to copy registration token
Diffstat (limited to 'server/models')
-rw-r--r--server/models/runner/runner-job.ts26
1 files changed, 18 insertions, 8 deletions
diff --git a/server/models/runner/runner-job.ts b/server/models/runner/runner-job.ts
index add6f9a43..f2ffd6a84 100644
--- a/server/models/runner/runner-job.ts
+++ b/server/models/runner/runner-job.ts
@@ -1,4 +1,4 @@
1import { FindOptions, Op, Transaction } from 'sequelize' 1import { Op, Transaction } from 'sequelize'
2import { 2import {
3 AllowNull, 3 AllowNull,
4 BelongsTo, 4 BelongsTo,
@@ -13,7 +13,7 @@ import {
13 Table, 13 Table,
14 UpdatedAt 14 UpdatedAt
15} from 'sequelize-typescript' 15} from 'sequelize-typescript'
16import { isUUIDValid } from '@server/helpers/custom-validators/misc' 16import { isArray, isUUIDValid } from '@server/helpers/custom-validators/misc'
17import { CONSTRAINTS_FIELDS, RUNNER_JOB_STATES } from '@server/initializers/constants' 17import { CONSTRAINTS_FIELDS, RUNNER_JOB_STATES } from '@server/initializers/constants'
18import { MRunnerJob, MRunnerJobRunner, MRunnerJobRunnerParent } from '@server/types/models/runners' 18import { MRunnerJob, MRunnerJobRunner, MRunnerJobRunnerParent } from '@server/types/models/runners'
19import { RunnerJob, RunnerJobAdmin, RunnerJobPayload, RunnerJobPrivatePayload, RunnerJobState, RunnerJobType } from '@shared/models' 19import { RunnerJob, RunnerJobAdmin, RunnerJobPayload, RunnerJobPrivatePayload, RunnerJobState, RunnerJobType } from '@shared/models'
@@ -227,28 +227,38 @@ export class RunnerJobModel extends Model<Partial<AttributesOnly<RunnerJobModel>
227 count: number 227 count: number
228 sort: string 228 sort: string
229 search?: string 229 search?: string
230 stateOneOf?: RunnerJobState[]
230 }) { 231 }) {
231 const { start, count, sort, search } = options 232 const { start, count, sort, search, stateOneOf } = options
232 233
233 const query: FindOptions = { 234 const query = {
234 offset: start, 235 offset: start,
235 limit: count, 236 limit: count,
236 order: getSort(sort) 237 order: getSort(sort),
238 where: []
237 } 239 }
238 240
239 if (search) { 241 if (search) {
240 if (isUUIDValid(search)) { 242 if (isUUIDValid(search)) {
241 query.where = { uuid: search } 243 query.where.push({ uuid: search })
242 } else { 244 } else {
243 query.where = { 245 query.where.push({
244 [Op.or]: [ 246 [Op.or]: [
245 searchAttribute(search, 'type'), 247 searchAttribute(search, 'type'),
246 searchAttribute(search, '$Runner.name$') 248 searchAttribute(search, '$Runner.name$')
247 ] 249 ]
248 } 250 })
249 } 251 }
250 } 252 }
251 253
254 if (isArray(stateOneOf) && stateOneOf.length !== 0) {
255 query.where.push({
256 state: {
257 [Op.in]: stateOneOf
258 }
259 })
260 }
261
252 return Promise.all([ 262 return Promise.all([
253 RunnerJobModel.scope([ ScopeNames.WITH_RUNNER ]).count(query), 263 RunnerJobModel.scope([ ScopeNames.WITH_RUNNER ]).count(query),
254 RunnerJobModel.scope([ ScopeNames.WITH_RUNNER, ScopeNames.WITH_PARENT ]).findAll<MRunnerJobRunnerParent>(query) 264 RunnerJobModel.scope([ ScopeNames.WITH_RUNNER, ScopeNames.WITH_PARENT ]).findAll<MRunnerJobRunnerParent>(query)