From f18003d0ac5c3fc6ec8de2a89102d1e1e89182df Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 27 Jul 2023 11:44:31 +0200 Subject: 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 --- server/models/runner/runner-job.ts | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'server/models/runner') 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 @@ -import { FindOptions, Op, Transaction } from 'sequelize' +import { Op, Transaction } from 'sequelize' import { AllowNull, BelongsTo, @@ -13,7 +13,7 @@ import { Table, UpdatedAt } from 'sequelize-typescript' -import { isUUIDValid } from '@server/helpers/custom-validators/misc' +import { isArray, isUUIDValid } from '@server/helpers/custom-validators/misc' import { CONSTRAINTS_FIELDS, RUNNER_JOB_STATES } from '@server/initializers/constants' import { MRunnerJob, MRunnerJobRunner, MRunnerJobRunnerParent } from '@server/types/models/runners' import { RunnerJob, RunnerJobAdmin, RunnerJobPayload, RunnerJobPrivatePayload, RunnerJobState, RunnerJobType } from '@shared/models' @@ -227,28 +227,38 @@ export class RunnerJobModel extends Model count: number sort: string search?: string + stateOneOf?: RunnerJobState[] }) { - const { start, count, sort, search } = options + const { start, count, sort, search, stateOneOf } = options - const query: FindOptions = { + const query = { offset: start, limit: count, - order: getSort(sort) + order: getSort(sort), + where: [] } if (search) { if (isUUIDValid(search)) { - query.where = { uuid: search } + query.where.push({ uuid: search }) } else { - query.where = { + query.where.push({ [Op.or]: [ searchAttribute(search, 'type'), searchAttribute(search, '$Runner.name$') ] - } + }) } } + if (isArray(stateOneOf) && stateOneOf.length !== 0) { + query.where.push({ + state: { + [Op.in]: stateOneOf + } + }) + } + return Promise.all([ RunnerJobModel.scope([ ScopeNames.WITH_RUNNER ]).count(query), RunnerJobModel.scope([ ScopeNames.WITH_RUNNER, ScopeNames.WITH_PARENT ]).findAll(query) -- cgit v1.2.3