<div class="actor-handle">
<span>@{{ account.nameWithHost }}</span>
- <button [cdkCopyToClipboard]="account.nameWithHostForced" (click)="activateCopiedMessage()"
- class="btn btn-outline-secondary btn-sm copy-button" title="Copy account handle" i18n-title
- >
- <my-global-icon iconName="copy"></my-global-icon>
- </button>
+
+ <my-copy-button
+ [value]="account.nameWithHostForced" i18n-notification notification="Username copied"
+ title="Copy account handle" i18n-title
+ ></my-copy-button>
</div>
<div class="actor-counters">
}
}
-.copy-button {
+my-copy-button {
@include margin-left(3px);
-
- border: 0;
-
- my-global-icon {
- width: 15px;
- }
}
.account-info {
this.redirectService.redirectToHomepage()
}
- activateCopiedMessage () {
- this.notifier.success($localize`Username copied`)
- }
-
searchChanged (search: string) {
const queryParams = { search }
<th style="width: 100px" i18n pSortableColumn="priority">Priority <p-sortIcon field="priority"></p-sortIcon></th>
<th style="width: 100px" i18n pSortableColumn="progress">Progress <p-sortIcon field="progress"></p-sortIcon></th>
<th i18n>Runner</th>
- <th style="width: 150px;" i18n pSortableColumn="createdAt">Created <p-sortIcon field="createdAt"></p-sortIcon></th>
+ <th style="width: 200px;" i18n pSortableColumn="createdAt">Created <p-sortIcon field="createdAt"></p-sortIcon></th>
</tr>
</ng-template>
</div>
<div class="ms-auto d-flex">
- <my-advanced-input-filter class="me-2" (search)="onSearch($event)"></my-advanced-input-filter>
+ <my-advanced-input-filter class="me-2" [filters]="inputFilters" (search)="onSearch($event)"></my-advanced-input-filter>
<my-button i18n-label label="Refresh" icon="refresh" (click)="reloadData()"></my-button>
</div>
<td>{{ runnerJob.uuid }}</td>
<td>{{ runnerJob.type }}</td>
- <td>{{ runnerJob.state.label }}</td>
+ <td>
+ <span class="pt-badge" [ngClass]="getStateBadgeColor(runnerJob)">{{ runnerJob.state.label }}</span>
+ </td>
<td>{{ runnerJob.priority }}</td>
<td>
import { DropdownAction } from '@app/shared/shared-main'
import { RunnerJob, RunnerJobState } from '@shared/models'
import { RunnerJobFormatted, RunnerService } from '../runner.service'
+import { AdvancedInputFilter } from '@app/shared/shared-forms'
@Component({
selector: 'my-runner-job-list',
actions: DropdownAction<RunnerJob>[][] = []
bulkActions: DropdownAction<RunnerJob[]>[][] = []
+ inputFilters: AdvancedInputFilter[] = [
+ {
+ title: $localize`Advanced filters`,
+ children: [
+ {
+ value: 'state:completed',
+ label: $localize`Completed jobs`
+ },
+ {
+ value: 'state:pending state:waiting-for-parent-job',
+ label: $localize`Pending jobs`
+ },
+ {
+ value: 'state:processing',
+ label: $localize`Jobs that are being processed`
+ },
+ {
+ value: 'state:errored state:parent-errored',
+ label: $localize`Failed jobs`
+ }
+ ]
+ }
+ ]
+
constructor (
private runnerService: RunnerService,
private notifier: Notifier,
handler: job => this.cancelJobs([ job ]),
isDisplayed: job => this.canCancelJob(job)
}
+ ],
+ [
+ {
+ label: $localize`Delete this job`,
+ handler: job => this.removeJobs([ job ])
+ }
]
]
handler: jobs => this.cancelJobs(jobs),
isDisplayed: jobs => jobs.every(j => this.canCancelJob(j))
}
+ ],
+ [
+ {
+ label: $localize`Delete`,
+ handler: jobs => this.removeJobs(jobs)
+ }
]
]
})
}
+ async removeJobs (jobs: RunnerJob[]) {
+ const message = formatICU(
+ $localize`Do you really want to remove {count, plural, =1 {this job} other {{count} jobs}}? Children jobs will also be removed.`,
+ { count: jobs.length }
+ )
+
+ const res = await this.confirmService.confirm(message, $localize`Remove`)
+
+ if (res === false) return
+
+ this.runnerService.removeJobs(jobs)
+ .subscribe({
+ next: () => {
+ this.reloadData()
+ this.notifier.success($localize`Job(s) removed.`)
+ },
+
+ error: err => this.notifier.error(err.message)
+ })
+ }
+
+ getStateBadgeColor (job: RunnerJob) {
+ switch (job.state.id) {
+ case RunnerJobState.ERRORED:
+ case RunnerJobState.PARENT_ERRORED:
+ return 'badge-danger'
+
+ case RunnerJobState.COMPLETED:
+ return 'badge-success'
+
+ case RunnerJobState.PENDING:
+ case RunnerJobState.WAITING_FOR_PARENT_JOB:
+ return 'badge-warning'
+
+ default:
+ return 'badge-info'
+ }
+ }
+
protected reloadDataInternal () {
this.runnerService.listRunnerJobs({ pagination: this.pagination, sort: this.sort, search: this.search })
.subscribe({
></my-action-dropdown>
</td>
- <td>{{ registrationToken.registrationToken }}</td>
+ <td>
+ {{ registrationToken.registrationToken }}
+
+ <my-copy-button
+ [value]="registrationToken.registrationToken" i18n-notification notification="Registration token copied"
+ i18n-title title="Copy registration token"
+ ></my-copy-button>
+ </td>
<td>{{ registrationToken.createdAt | date: 'short' }}</td>
--- /dev/null
+@use '_variables' as *;
+@use '_mixins' as *;
+
+my-copy-button {
+ @include margin-left(3px);
+}
+
+tr:not(:hover) {
+ my-copy-button {
+ opacity: 0;
+ }
+}
@Component({
selector: 'my-runner-registration-token-list',
+ styleUrls: [ './runner-registration-token-list.component.scss' ],
templateUrl: './runner-registration-token-list.component.html'
})
export class RunnerRegistrationTokenListComponent extends RestTable <RunnerRegistrationToken> implements OnInit {
import { RestExtractor, RestPagination, RestService, ServerService } from '@app/core'
import { arrayify, peertubeTranslate } from '@shared/core-utils'
import { ResultList } from '@shared/models/common'
-import { Runner, RunnerJob, RunnerJobAdmin, RunnerRegistrationToken } from '@shared/models/runners'
+import { Runner, RunnerJob, RunnerJobAdmin, RunnerJobState, RunnerRegistrationToken } from '@shared/models/runners'
import { environment } from '../../../../environments/environment'
export type RunnerJobFormatted = RunnerJob & {
let params = new HttpParams()
params = this.restService.addRestGetParams(params, pagination, sort)
- if (search) params = params.append('search', search)
+ if (search) {
+ params = this.buildParamsFromSearch(search, params)
+ }
return forkJoin([
this.authHttp.get<ResultList<RunnerJobAdmin>>(RunnerService.BASE_RUNNER_URL + '/jobs', { params }),
)
}
+ private buildParamsFromSearch (search: string, params: HttpParams) {
+ const filters = this.restService.parseQueryStringFilter(search, {
+ stateOneOf: {
+ prefix: 'state:',
+ multiple: true,
+ handler: v => {
+ if (v === 'completed') return RunnerJobState.COMPLETED
+ if (v === 'processing') return RunnerJobState.PROCESSING
+ if (v === 'errored') return RunnerJobState.ERRORED
+ if (v === 'pending') return RunnerJobState.PENDING
+ if (v === 'waiting-for-parent-job') return RunnerJobState.WAITING_FOR_PARENT_JOB
+ if (v === 'parent-errored') return RunnerJobState.PARENT_ERRORED
+
+ return undefined
+ }
+ }
+ })
+
+ console.log(filters)
+
+ return this.restService.addObjectParams(params, filters)
+ }
+
+ // ---------------------------------------------------------------------------
+
cancelJobs (jobsArg: RunnerJob | RunnerJob[]) {
const jobs = arrayify(jobsArg)
)
}
+ removeJobs (jobsArg: RunnerJob | RunnerJob[]) {
+ const jobs = arrayify(jobsArg)
+
+ return from(jobs)
+ .pipe(
+ concatMap(job => this.authHttp.delete(RunnerService.BASE_RUNNER_URL + '/jobs/' + job.uuid)),
+ toArray(),
+ catchError(err => this.restExtractor.handleError(err))
+ )
+ }
+
// ---------------------------------------------------------------------------
listRunners (options: {
<div class="actor-handle">
<span>@{{ videoChannel.nameWithHost }}</span>
- <button [cdkCopyToClipboard]="videoChannel.nameWithHostForced" (click)="activateCopiedMessage()"
- class="btn btn-outline-secondary btn-sm copy-button" title="Copy channel handle" i18n-title
- >
- <my-global-icon iconName="copy"></my-global-icon>
- </button>
+
+ <my-copy-button
+ [value]="videoChannel.nameWithHostForced" i18n-notification notification="Handle copied"
+ title="Copy channel handle" i18n-title
+ ></my-copy-button>
</div>
<div class="actor-counters">
display: none;
}
-.copy-button {
+my-copy-button {
@include margin-left(3px);
-
- border: 0;
-
- my-global-icon {
- width: 15px;
- }
}
@media screen and (max-width: 1400px) {
return this.isOwner() || this.authService.getUser().hasRight(UserRight.MANAGE_ANY_VIDEO_CHANNEL)
}
- activateCopiedMessage () {
- this.notifier.success($localize`Username copied`)
- }
-
hasShowMoreDescription () {
return !this.channelDescriptionExpanded && this.channelDescriptionHTML.length > 100
}
const debugLogger = debug('peertube:rest')
+type ParseQueryHandlerResult = string | number | boolean | string[] | number[] | boolean[]
+
interface QueryStringFilterPrefixes {
[key: string]: {
prefix: string
- handler?: (v: string) => string | number | boolean
+ handler?: (v: string) => ParseQueryHandlerResult
multiple?: boolean
isBoolean?: boolean
}
}
-type ParseQueryStringFilters <K extends keyof any> = Partial<Record<K, string | number | boolean | (string | number | boolean)[]>>
+type ParseQueryStringFilters <K extends keyof any> = Partial<Record<K, ParseQueryHandlerResult | ParseQueryHandlerResult[]>>
type ParseQueryStringFiltersResult <K extends keyof any> = ParseQueryStringFilters<K> & { search?: string }
@Injectable()
div[role=menu] {
max-height: 50vh;
- min-height: 200px;
overflow: auto;
}
<my-global-icon *ngIf="!show" iconName="eye-close"></my-global-icon>
</button>
- <button
- *ngIf="withCopy" [cdkCopyToClipboard]="input.value" (click)="activateCopiedMessage()" type="button"
- class="btn btn-outline-secondary text-uppercase" i18n-title title="Copy"
+ <my-copy-button
+ *ngIf="withCopy" [value]="input.value" i18n-notification notification="Copied"
+ [isInputGroup]="true" i18n
>
- <my-global-icon iconName="copy"></my-global-icon>
- <span class="copy-text">Copy</span>
- </button>
+ COPY
+ </my-copy-button>
</div>
<div *ngIf="formError" class="form-error">{{ formError }}</div>
this.show = !this.show
}
- activateCopiedMessage () {
- this.notifier.success($localize`Copied`)
- }
-
propagateChange = (_: any) => { /* empty */ }
writeValue (value: string) {
--- /dev/null
+<button
+ class="btn btn-outline-secondary btn-sm copy-button"
+ [cdkCopyToClipboard]="value" (click)="activateCopiedMessage()"
+ [title]="title" [ngClass]="{ 'is-input-group': isInputGroup }"
+>
+ <my-global-icon iconName="copy"></my-global-icon>
+
+ <ng-content></ng-content>
+</button>
--- /dev/null
+@use '_variables' as *;
+@use '_mixins' as *;
+
+button:not(.is-input-group) {
+ border: 0;
+}
+
+.is-input-group {
+ border-top-left-radius: 0;
+ border-bottom-left-radius: 0;
+}
+
+my-global-icon {
+ width: 15px;
+}
--- /dev/null
+import { Component, Input } from '@angular/core'
+import { Notifier } from '@app/core'
+
+@Component({
+ selector: 'my-copy-button',
+ styleUrls: [ './copy-button.component.scss' ],
+ templateUrl: './copy-button.component.html'
+})
+export class CopyButtonComponent {
+ @Input() value: string
+ @Input() title: string
+ @Input() notification: string
+ @Input() isInputGroup = false
+
+ constructor (private notifier: Notifier) {
+
+ }
+
+ activateCopiedMessage () {
+ if (this.notification) this.notifier.success(this.notification)
+ }
+}
export * from './action-dropdown.component'
export * from './button.component'
+export * from './copy-button.component'
export * from './delete-button.component'
export * from './edit-button.component'
PeerTubeTemplateDirective
} from './angular'
import { AUTH_INTERCEPTOR_PROVIDER } from './auth'
-import { ActionDropdownComponent, ButtonComponent, DeleteButtonComponent, EditButtonComponent } from './buttons'
+import { ActionDropdownComponent, ButtonComponent, CopyButtonComponent, DeleteButtonComponent, EditButtonComponent } from './buttons'
import { CustomPageService } from './custom-page'
import { DateToggleComponent } from './date'
import { FeedComponent } from './feeds'
ActionDropdownComponent,
ButtonComponent,
+ CopyButtonComponent,
DeleteButtonComponent,
EditButtonComponent,
ActionDropdownComponent,
ButtonComponent,
+ CopyButtonComponent,
DeleteButtonComponent,
EditButtonComponent,
import { generateRunnerJobToken } from '@server/helpers/token-generator'
import { MIMETYPES } from '@server/initializers/constants'
import { sequelizeTypescript } from '@server/initializers/database'
-import { getRunnerJobHandlerClass, updateLastRunnerContact } from '@server/lib/runners'
+import { getRunnerJobHandlerClass, runnerJobCanBeCancelled, updateLastRunnerContact } from '@server/lib/runners'
import {
apiRateLimiter,
asyncMiddleware,
errorRunnerJobValidator,
getRunnerFromTokenValidator,
jobOfRunnerGetValidatorFactory,
+ listRunnerJobsValidator,
runnerJobGetValidator,
successRunnerJobValidator,
updateRunnerJobValidator
runnerJobsSortValidator,
setDefaultSort,
setDefaultPagination,
+ listRunnerJobsValidator,
asyncMiddleware(listRunnerJobs)
)
+runnerJobsRouter.delete('/jobs/:jobUUID',
+ authenticate,
+ ensureUserHasRight(UserRight.MANAGE_RUNNERS),
+ asyncMiddleware(runnerJobGetValidator),
+ asyncMiddleware(deleteRunnerJob)
+)
+
// ---------------------------------------------------------------------------
export {
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
}
+async function deleteRunnerJob (req: express.Request, res: express.Response) {
+ const runnerJob = res.locals.runnerJob
+
+ logger.info('Deleting job %s (%s)', runnerJob.uuid, runnerJob.type, lTags(runnerJob.uuid, runnerJob.type))
+
+ if (runnerJobCanBeCancelled(runnerJob)) {
+ const RunnerJobHandler = getRunnerJobHandlerClass(runnerJob)
+ await new RunnerJobHandler().cancel({ runnerJob })
+ }
+
+ await runnerJob.destroy()
+
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+}
+
async function listRunnerJobs (req: express.Request, res: express.Response) {
const query: ListRunnerJobsQuery = req.query
start: query.start,
count: query.count,
sort: query.sort,
- search: query.search
+ search: query.search,
+ stateOneOf: query.stateOneOf
})
return res.json({
import { UploadFilesForCheck } from 'express'
import validator from 'validator'
-import { CONSTRAINTS_FIELDS } from '@server/initializers/constants'
+import { CONSTRAINTS_FIELDS, RUNNER_JOB_STATES } from '@server/initializers/constants'
import {
LiveRTMPHLSTranscodingSuccess,
RunnerJobSuccessPayload,
VODHLSTranscodingSuccess,
VODWebVideoTranscodingSuccess
} from '@shared/models'
-import { exists, isFileValid, isSafeFilename } from '../misc'
+import { exists, isArray, isFileValid, isSafeFilename } from '../misc'
const RUNNER_JOBS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.RUNNER_JOBS
return validator.isLength(value, RUNNER_JOBS_CONSTRAINTS_FIELDS.ERROR_MESSAGE)
}
+function isRunnerJobStateValid (value: any) {
+ return exists(value) && RUNNER_JOB_STATES[value] !== undefined
+}
+
+function isRunnerJobArrayOfStateValid (value: any) {
+ return isArray(value) && value.every(v => isRunnerJobStateValid(v))
+}
+
// ---------------------------------------------------------------------------
export {
isRunnerJobTokenValid,
isRunnerJobErrorMessageValid,
isRunnerJobProgressValid,
- isRunnerJobAbortReasonValid
+ isRunnerJobAbortReasonValid,
+ isRunnerJobArrayOfStateValid,
+ isRunnerJobStateValid
}
// ---------------------------------------------------------------------------
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'
+import { MRunner, MRunnerJob } from '@server/types/models/runners'
import { RUNNER_JOBS } from '@server/initializers/constants'
+import { RunnerJobState } from '@shared/models'
const lTags = loggerTagsFactory('runner')
.finally(() => updatingRunner.delete(runner.id))
}
+function runnerJobCanBeCancelled (runnerJob: MRunnerJob) {
+ const allowedStates = new Set<RunnerJobState>([
+ RunnerJobState.PENDING,
+ RunnerJobState.PROCESSING,
+ RunnerJobState.WAITING_FOR_PARENT_JOB
+ ])
+
+ return allowedStates.has(runnerJob.state)
+}
+
export {
- updateLastRunnerContact
+ updateLastRunnerContact,
+ runnerJobCanBeCancelled
}
import express from 'express'
-import { body, param } from 'express-validator'
-import { isUUIDValid } from '@server/helpers/custom-validators/misc'
+import { body, param, query } from 'express-validator'
+import { exists, isUUIDValid } from '@server/helpers/custom-validators/misc'
import {
isRunnerJobAbortReasonValid,
+ isRunnerJobArrayOfStateValid,
isRunnerJobErrorMessageValid,
isRunnerJobProgressValid,
isRunnerJobSuccessPayloadValid,
import { isRunnerTokenValid } from '@server/helpers/custom-validators/runners/runners'
import { cleanUpReqFiles } from '@server/helpers/express-utils'
import { LiveManager } from '@server/lib/live'
+import { runnerJobCanBeCancelled } from '@server/lib/runners'
import { RunnerJobModel } from '@server/models/runner/runner-job'
+import { arrayify } from '@shared/core-utils'
import {
HttpStatusCode,
RunnerJobLiveRTMPHLSTranscodingPrivatePayload,
(req: express.Request, res: express.Response, next: express.NextFunction) => {
const runnerJob = res.locals.runnerJob
- const allowedStates = new Set<RunnerJobState>([
- RunnerJobState.PENDING,
- RunnerJobState.PROCESSING,
- RunnerJobState.WAITING_FOR_PARENT_JOB
- ])
-
- if (allowedStates.has(runnerJob.state) !== true) {
+ if (runnerJobCanBeCancelled(runnerJob) !== true) {
return res.fail({
status: HttpStatusCode.BAD_REQUEST_400,
message: 'Cannot cancel this job that is not in "pending", "processing" or "waiting for parent job" state',
}
]
+export const listRunnerJobsValidator = [
+ query('search')
+ .optional()
+ .custom(exists),
+
+ query('stateOneOf')
+ .optional()
+ .customSanitizer(arrayify)
+ .custom(isRunnerJobArrayOfStateValid),
+
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ return next()
+ }
+]
+
export const runnerJobGetValidator = [
param('jobUUID').custom(isUUIDValid),
-import { FindOptions, Op, Transaction } from 'sequelize'
+import { Op, Transaction } from 'sequelize'
import {
AllowNull,
BelongsTo,
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'
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<MRunnerJobRunnerParent>(query)
-import { basename } from 'path'
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
+import { basename } from 'path'
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
import {
HttpStatusCode,
isVideoStudioTaskIntro,
RunnerJob,
RunnerJobState,
+ RunnerJobStudioTranscodingPayload,
RunnerJobSuccessPayload,
RunnerJobUpdatePayload,
- RunnerJobStudioTranscodingPayload,
VideoPrivacy,
VideoStudioTaskIntro
} from '@shared/models'
await checkBadSortPagination(server.url, path, server.accessToken)
})
+ it('Should fail with an invalid state', async function () {
+ await server.runners.list({ start: 0, count: 5, sort: '-createdAt' })
+ })
+
it('Should succeed to list with the correct params', async function () {
await server.runners.list({ start: 0, count: 5, sort: '-createdAt' })
})
await checkBadSortPagination(server.url, path, server.accessToken)
})
- it('Should succeed to list with the correct params', async function () {
- await server.runnerJobs.list({ start: 0, count: 5, sort: '-createdAt' })
+ it('Should fail with an invalid state', async function () {
+ await server.runnerJobs.list({ start: 0, count: 5, sort: '-createdAt', stateOneOf: 42 as any })
+ await server.runnerJobs.list({ start: 0, count: 5, sort: '-createdAt', stateOneOf: [ 42 ] as any })
+ })
+
+ it('Should succeed with the correct params', async function () {
+ await server.runnerJobs.list({ start: 0, count: 5, sort: '-createdAt', stateOneOf: [ RunnerJobState.COMPLETED ] })
+ })
+ })
+
+ describe('Delete', function () {
+ let jobUUID: string
+
+ before(async function () {
+ this.timeout(60000)
+
+ await server.videos.quickUpload({ name: 'video' })
+ await waitJobs([ server ])
+
+ const { availableJobs } = await server.runnerJobs.request({ runnerToken })
+ jobUUID = availableJobs[0].uuid
+ })
+
+ it('Should fail without oauth token', async function () {
+ await server.runnerJobs.deleteByAdmin({ token: null, jobUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
+ })
+
+ it('Should fail without admin rights', async function () {
+ await server.runnerJobs.deleteByAdmin({ token: userToken, jobUUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
+ })
+
+ it('Should fail with a bad job uuid', async function () {
+ await server.runnerJobs.deleteByAdmin({ jobUUID: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
+ })
+
+ it('Should fail with an unknown job uuid', async function () {
+ const jobUUID = badUUID
+ await server.runnerJobs.deleteByAdmin({ jobUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
+ })
+
+ it('Should succeed with the correct params', async function () {
+ await server.runnerJobs.deleteByAdmin({ jobUUID })
})
})
expect(data).to.not.have.lengthOf(0)
expect(total).to.not.equal(0)
+
+ for (const job of data) {
+ expect(job.type).to.include('hls')
+ }
+ }
+ })
+
+ it('Should filter jobs', async function () {
+ {
+ const { total, data } = await server.runnerJobs.list({ stateOneOf: [ RunnerJobState.WAITING_FOR_PARENT_JOB ] })
+
+ expect(data).to.not.have.lengthOf(0)
+ expect(total).to.not.equal(0)
+
+ for (const job of data) {
+ expect(job.state.label).to.equal('Waiting for parent job to finish')
+ }
+ }
+
+ {
+ const { total, data } = await server.runnerJobs.list({ stateOneOf: [ RunnerJobState.COMPLETED ] })
+
+ expect(data).to.have.lengthOf(0)
+ expect(total).to.equal(0)
}
})
})
})
})
+ describe('Remove', function () {
+
+ it('Should remove a pending job', async function () {
+ await server.videos.quickUpload({ name: 'video' })
+ await waitJobs([ server ])
+
+ {
+ const { data } = await server.runnerJobs.list({ count: 10, sort: '-updatedAt' })
+
+ const pendingJob = data.find(j => j.state.id === RunnerJobState.PENDING)
+ jobUUID = pendingJob.uuid
+
+ await server.runnerJobs.deleteByAdmin({ jobUUID })
+ }
+
+ {
+ const { data } = await server.runnerJobs.list({ count: 10, sort: '-updatedAt' })
+
+ const parent = data.find(j => j.uuid === jobUUID)
+ expect(parent).to.not.exist
+
+ const children = data.filter(j => j.parent?.uuid === jobUUID)
+ expect(children).to.have.lengthOf(0)
+ }
+ })
+ })
+
describe('Stalled jobs', function () {
it('Should abort stalled jobs', async function () {
+import { RunnerJobState } from './runner-job-state.model'
+
export interface ListRunnerJobsQuery {
start?: number
count?: number
sort?: string
search?: string
+ stateOneOf?: RunnerJobState[]
}
isHLSTranscodingPayloadSuccess,
isLiveRTMPHLSTranscodingUpdatePayload,
isWebVideoOrAudioMergeTranscodingPayloadSuccess,
+ ListRunnerJobsQuery,
RequestRunnerJobBody,
RequestRunnerJobResult,
ResultList,
export class RunnerJobsCommand extends AbstractCommand {
- list (options: OverrideCommandOptions & {
- start?: number
- count?: number
- sort?: string
- search?: string
- } = {}) {
+ list (options: OverrideCommandOptions & ListRunnerJobsQuery = {}) {
const path = '/api/v1/runners/jobs'
return this.getRequestBody<ResultList<RunnerJobAdmin>>({
...options,
path,
- query: pick(options, [ 'start', 'count', 'sort', 'search' ]),
+ query: pick(options, [ 'start', 'count', 'sort', 'search', 'stateOneOf' ]),
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
})
}
+ deleteByAdmin (options: OverrideCommandOptions & { jobUUID: string }) {
+ const path = '/api/v1/runners/jobs/' + options.jobUUID
+
+ return this.deleteRequest({
+ ...options,
+
+ path,
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
// ---------------------------------------------------------------------------
request (options: OverrideCommandOptions & RequestRunnerJobBody) {
'204':
description: successful operation
+ /api/v1/runners/jobs/{jobUUID}:
+ delete:
+ summary: Delete a job
+ description: The endpoint will first cancel the job if needed, and then remove it from the database. Children jobs will also be removed
+ security:
+ - OAuth2:
+ - admin
+ tags:
+ - Runner Jobs
+ parameters:
+ - $ref: '#/components/parameters/jobUUID'
+ responses:
+ '204':
+ description: successful operation
+
/api/v1/runners/jobs:
get:
summary: List jobs
- $ref: '#/components/parameters/count'
- $ref: '#/components/parameters/runnerJobSort'
- $ref: '#/components/parameters/search'
+ - name: stateOneOf
+ in: query
+ required: false
+ schema:
+ type: array
+ items:
+ $ref: '#/components/schemas/RunnerJobState'
responses:
'200':
description: successful operation