ActivityPub-federated video streaming platform using P2P directly in your web browser
add display of logs matching any state
Rigel Kent040d6896a3cd
diff --git a/client/src/app/+admin/system/jobs/job.service.ts b/client/src/app/+admin/system/jobs/job.service.tsindex 1ac50f050f..4b4a8914fd 100644--- a/client/src/app/+admin/system/jobs/job.service.ts+++ b/client/src/app/+admin/system/jobs/job.service.ts@@ -19,13 +19,20 @@ export class JobService {private restExtractor: RestExtractor) {}- getJobs (jobState: JobStateClient, jobType: JobTypeClient, pagination: RestPagination, sort: SortMeta): Observable<ResultList<Job>> {+ getJobs (options: {+ jobState?: JobStateClient,+ jobType: JobTypeClient,+ pagination: RestPagination,+ sort: SortMeta+ }): Observable<ResultList<Job>> {+ const { jobState, jobType, pagination, sort } = options+let params = new HttpParams()params = this.restService.addRestGetParams(params, pagination, sort)if (jobType !== 'all') params = params.append('jobType', jobType)- return this.authHttp.get<ResultList<Job>>(JobService.BASE_JOB_URL + '/' + jobState, { params })+ return this.authHttp.get<ResultList<Job>>(JobService.BASE_JOB_URL + `/${jobState ? jobState : ''}`, { params }).pipe(map(res => {return this.restExtractor.convertResultListDateToHuman(res, [ 'createdAt', 'processedOn', 'finishedOn' ])diff --git a/client/src/app/+admin/system/jobs/jobs.component.html b/client/src/app/+admin/system/jobs/jobs.component.htmlindex e06156a9e3..2d60e7b9ed 100644--- a/client/src/app/+admin/system/jobs/jobs.component.html+++ b/client/src/app/+admin/system/jobs/jobs.component.html@@ -17,6 +17,9 @@[clearable]="false"[searchable]="false">+ <ng-option value="all">+ <span i18n="Selector for the list displaying jobs, filtering by their state">any</span>+ </ng-option><ng-option *ngFor="let state of jobStates" [value]="state"><span class="badge" [ngClass]="getJobStateClass(state)">{{ state }}</span></ng-option>@@ -37,27 +40,31 @@<th style="width: 40px"></th><th style="width: calc(100% - 390px)" class="job-id" i18n>ID</th><th style="width: 200px" class="job-type" i18n>Type</th>+ <th style="width: 200px" class="job-type" i18n *ngIf="jobState === 'all'">State</th><th style="width: 150px" class="job-date" i18n pSortableColumn="createdAt">Created <p-sortIcon field="createdAt"></p-sortIcon></th></tr></ng-template><ng-template pTemplate="body" let-expanded="expanded" let-job><tr>- <td class="expand-cell" [pRowToggler]="job" i18n-ngbTooltip ngbTooltip="More information" placement="top-left" container="body">+ <td class="expand-cell c-hand" [pRowToggler]="job" i18n-ngbTooltip ngbTooltip="More information" placement="top-left" container="body"><span class="expander"><i [ngClass]="expanded ? 'glyphicon glyphicon-menu-down' : 'glyphicon glyphicon-menu-right'"></i></span></td>- <td class="job-id" [pRowToggler]="job" [title]="job.id">{{ job.id }}</td>- <td class="job-type" [pRowToggler]="job">{{ job.type }}</td>- <td class="job-date" [pRowToggler]="job">{{ job.createdAt | date: 'short' }}</td>+ <td class="job-id c-hand" [pRowToggler]="job" [title]="job.id">{{ job.id }}</td>+ <td class="job-type c-hand" [pRowToggler]="job">{{ job.type }}</td>+ <td class="job-type c-hand" [pRowToggler]="job" *ngIf="jobState === 'all'">+ <span class="badge" [ngClass]="getJobStateClass(job.state)">{{ job.state }}</span>+ </td>+ <td class="job-date c-hand" [pRowToggler]="job">{{ job.createdAt | date: 'short' }}</td></tr></ng-template><ng-template pTemplate="rowexpansion" let-job><tr>- <td colspan="4">+ <td [attr.colspan]="getColspan()"><pre>{{ ['Job: ' + job.id,'Type: ' + job.type,@@ -67,12 +74,12 @@</td></tr><tr>- <td colspan="4">+ <td [attr.colspan]="getColspan()"><pre>{{ job.data }}</pre></td></tr><tr class="job-error" *ngIf="job.error">- <td colspan="4">+ <td [attr.colspan]="getColspan()"><pre>{{ job.error }}</pre></td></tr>@@ -80,11 +87,17 @@<ng-template pTemplate="emptymessage"><tr>- <td colspan="4">+ <td [attr.colspan]="getColspan()"><div class="no-results"><div class="d-block">- <ng-container *ngIf="jobType === 'all'" i18n>No <span class="badge" [ngClass]="getJobStateClass(jobState)">{{ jobState }}</span> jobs found.</ng-container>- <ng-container *ngIf="jobType !== 'all'" i18n>No <code>{{ jobType }}</code> jobs found that are <span class="badge" [ngClass]="getJobStateClass(jobState)">{{ jobState }}</span>.</ng-container>+ <ng-container *ngIf="jobState === 'all'">+ <ng-container *ngIf="jobType === 'all'" i18n>No jobs found.</ng-container>+ <ng-container *ngIf="jobType !== 'all'" i18n>No <code>{{ jobType }}</code> jobs found.</ng-container>+ </ng-container>+ <ng-container *ngIf="jobState !== 'all'">+ <ng-container *ngIf="jobType === 'all'" i18n>No <span class="badge" [ngClass]="getJobStateClass(jobState)">{{ jobState }}</span> jobs found.</ng-container>+ <ng-container *ngIf="jobType !== 'all'" i18n>No <code>{{ jobType }}</code> jobs found that are <span class="badge" [ngClass]="getJobStateClass(jobState)">{{ jobState }}</span>.</ng-container>+ </ng-container></div></div></td>diff --git a/client/src/app/+admin/system/jobs/jobs.component.ts b/client/src/app/+admin/system/jobs/jobs.component.tsindex f8e12d1b61..b7f18067b8 100644--- a/client/src/app/+admin/system/jobs/jobs.component.ts+++ b/client/src/app/+admin/system/jobs/jobs.component.ts@@ -16,7 +16,7 @@ export class JobsComponent extends RestTable implements OnInit {private static LOCAL_STORAGE_STATE = 'jobs-list-state'private static LOCAL_STORAGE_TYPE = 'jobs-list-type'- jobState: JobStateClient = 'waiting'+ jobState?: JobStateClient | 'all'jobStates: JobStateClient[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ]jobType: JobTypeClient = 'all'@@ -73,6 +73,10 @@ export class JobsComponent extends RestTable implements OnInit {}}+ getColspan () {+ return this.jobState === 'all' ? 5 : 4+ }+onJobStateOrTypeChanged () {this.pagination.start = 0@@ -81,8 +85,16 @@ export class JobsComponent extends RestTable implements OnInit {}protected loadData () {+ let jobState = this.jobState as JobState+ if (this.jobState === 'all') jobState = null+this.jobsService- .getJobs(this.jobState, this.jobType, this.pagination, this.sort)+ .getJobs({+ jobState,+ jobType: this.jobType,+ pagination: this.pagination,+ sort: this.sort+ }).subscribe(resultList => {this.jobs = resultList.datadiff --git a/server/controllers/api/jobs.ts b/server/controllers/api/jobs.tsindex ed6c945335..1131a44d60 100644--- a/server/controllers/api/jobs.ts+++ b/server/controllers/api/jobs.ts@@ -12,11 +12,23 @@ import {setDefaultSort} from '../../middlewares'import { paginationValidator } from '../../middlewares/validators'-import { listJobsValidator } from '../../middlewares/validators/jobs'+import { listJobsStateValidator, listJobsValidator } from '../../middlewares/validators/jobs'import { isArray } from '../../helpers/custom-validators/misc'+import { jobStates } from '@server/helpers/custom-validators/jobs'const jobsRouter = express.Router()+jobsRouter.get('/',+ authenticate,+ ensureUserHasRight(UserRight.MANAGE_JOBS),+ paginationValidator,+ jobsSortValidator,+ setDefaultSort,+ setDefaultPagination,+ listJobsValidator,+ asyncMiddleware(listJobs)+)+jobsRouter.get('/:state',authenticate,ensureUserHasRight(UserRight.MANAGE_JOBS),@@ -25,6 +37,7 @@ jobsRouter.get('/:state',setDefaultSort,setDefaultPagination,listJobsValidator,+ listJobsStateValidator,asyncMiddleware(listJobs))@@ -37,7 +50,7 @@ export {// ---------------------------------------------------------------------------async function listJobs (req: express.Request, res: express.Response) {- const state = req.params.state as JobState+ const state = req.params.state as JobState || jobStatesconst asc = req.query.sort === 'createdAt'const jobType = req.query.jobType@@ -52,7 +65,11 @@ async function listJobs (req: express.Request, res: express.Response) {const result: ResultList<Job> = {total,- data: jobs.map(j => formatJob(j, state))+ data: Array.isArray(state)+ ? await Promise.all(+ jobs.map(async j => formatJob(j, await j.getState() as JobState))+ )+ : jobs.map(j => formatJob(j, state))}return res.json(result)}diff --git a/server/helpers/custom-validators/jobs.ts b/server/helpers/custom-validators/jobs.tsindex dd33e85a39..72dc73ee44 100644--- a/server/helpers/custom-validators/jobs.ts+++ b/server/helpers/custom-validators/jobs.ts@@ -15,6 +15,7 @@ function isValidJobType (value: any) {// ---------------------------------------------------------------------------export {+ jobStates,isValidJobState,isValidJobType}diff --git a/server/lib/job-queue/job-queue.ts b/server/lib/job-queue/job-queue.tsindex 8d97434ac5..49f06584dc 100644--- a/server/lib/job-queue/job-queue.ts+++ b/server/lib/job-queue/job-queue.ts@@ -154,13 +154,13 @@ class JobQueue {}async listForApi (options: {- state: JobState+ state: JobState | JobState[]start: numbercount: numberasc?: booleanjobType: JobType}): Promise<Bull.Job[]> {- const { state, start, count, asc, jobType } = options+ const { state = Array.isArray(options.state) ? options.state : [ options.state ], start, count, asc, jobType } = optionslet results: Bull.Job[] = []const filteredJobTypes = this.filterJobTypes(jobType)@@ -172,7 +172,7 @@ class JobQueue {continue}- const jobs = await queue.getJobs([ state ], 0, start + count, asc)+ const jobs = await queue.getJobs(state as Bull.JobStatus[], 0, start + count, asc)results = results.concat(jobs)}@@ -188,7 +188,8 @@ class JobQueue {return results.slice(start, start + count)}- async count (state: JobState, jobType?: JobType): Promise<number> {+ async count (state: JobState | JobState[], jobType?: JobType): Promise<number> {+ const states = Array.isArray(state) ? state : [ state ]let total = 0const filteredJobTypes = this.filterJobTypes(jobType)@@ -202,7 +203,9 @@ class JobQueue {const counts = await queue.getJobCounts()- total += counts[state]+ for (const s of states) {+ total += counts[s]+ }}return totaldiff --git a/server/middlewares/validators/jobs.ts b/server/middlewares/validators/jobs.tsindex b57615dbcb..0fc183c1af 100644--- a/server/middlewares/validators/jobs.ts+++ b/server/middlewares/validators/jobs.ts@@ -5,8 +5,6 @@ import { logger } from '../../helpers/logger'import { areValidationErrors } from './utils'const listJobsValidator = [- param('state')- .custom(isValidJobState).not().isEmpty().withMessage('Should have a valid job state'),query('jobType').optional().custom(isValidJobType).withMessage('Should have a valid job state'),@@ -20,8 +18,22 @@ const listJobsValidator = [}]+const listJobsStateValidator = [+ param('state')+ .custom(isValidJobState).not().isEmpty().withMessage('Should have a valid job state'),++ (req: express.Request, res: express.Response, next: express.NextFunction) => {+ logger.debug('Checking listJobsValidator parameters.', { parameters: req.params })++ if (areValidationErrors(req, res)) return++ return next()+ }+]+// ---------------------------------------------------------------------------export {- listJobsValidator+ listJobsValidator,+ listJobsStateValidator}diff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yamlindex ba420b4a96..c06bffb0a1 100644--- a/support/doc/api/openapi.yaml+++ b/support/doc/api/openapi.yaml@@ -356,15 +356,17 @@ paths:- name: statein: pathrequired: true- description: The state of the job+ description: The state of the job ('' for for no filter)schema:type: stringenum:+ - ''- active- completed- failed- waiting- delayed+ - $ref: '#/components/parameters/jobType'- $ref: '#/components/parameters/start'- $ref: '#/components/parameters/count'- $ref: '#/components/parameters/sort'@@ -3780,6 +3782,26 @@ components:schema:type: stringexample: peertube-plugin-auth-ldap+ jobType:+ name: jobType+ in: query+ required: false+ description: job type+ schema:+ type: string+ enum:+ - activitypub-follow+ - activitypub-http-broadcast+ - activitypub-http-fetcher+ - activitypub-http-unicast+ - video-transcoding+ - video-file-import+ - video-import+ - videos-views+ - activitypub-refresher+ - video-redundancy+ - video-live-endingsecuritySchemes:OAuth2:description: >