add display of logs matching any state

This commit is contained in:
Rigel Kent 2020-12-13 19:27:25 +01:00
parent 7aebd32f83
commit 040d6896a3
No known key found for this signature in database
GPG Key ID: 5E53E96A494E452F
8 changed files with 113 additions and 26 deletions

View File

@ -19,13 +19,20 @@ export class JobService {
private restExtractor: RestExtractor 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() let params = new HttpParams()
params = this.restService.addRestGetParams(params, pagination, sort) params = this.restService.addRestGetParams(params, pagination, sort)
if (jobType !== 'all') params = params.append('jobType', jobType) 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( .pipe(
map(res => { map(res => {
return this.restExtractor.convertResultListDateToHuman(res, [ 'createdAt', 'processedOn', 'finishedOn' ]) return this.restExtractor.convertResultListDateToHuman(res, [ 'createdAt', 'processedOn', 'finishedOn' ])

View File

@ -17,6 +17,9 @@
[clearable]="false" [clearable]="false"
[searchable]="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"> <ng-option *ngFor="let state of jobStates" [value]="state">
<span class="badge" [ngClass]="getJobStateClass(state)">{{ state }}</span> <span class="badge" [ngClass]="getJobStateClass(state)">{{ state }}</span>
</ng-option> </ng-option>
@ -37,27 +40,31 @@
<th style="width: 40px"></th> <th style="width: 40px"></th>
<th style="width: calc(100% - 390px)" class="job-id" i18n>ID</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>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> <th style="width: 150px" class="job-date" i18n pSortableColumn="createdAt">Created <p-sortIcon field="createdAt"></p-sortIcon></th>
</tr> </tr>
</ng-template> </ng-template>
<ng-template pTemplate="body" let-expanded="expanded" let-job> <ng-template pTemplate="body" let-expanded="expanded" let-job>
<tr> <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"> <span class="expander">
<i [ngClass]="expanded ? 'glyphicon glyphicon-menu-down' : 'glyphicon glyphicon-menu-right'"></i> <i [ngClass]="expanded ? 'glyphicon glyphicon-menu-down' : 'glyphicon glyphicon-menu-right'"></i>
</span> </span>
</td> </td>
<td class="job-id" [pRowToggler]="job" [title]="job.id">{{ job.id }}</td> <td class="job-id c-hand" [pRowToggler]="job" [title]="job.id">{{ job.id }}</td>
<td class="job-type" [pRowToggler]="job">{{ job.type }}</td> <td class="job-type c-hand" [pRowToggler]="job">{{ job.type }}</td>
<td class="job-date" [pRowToggler]="job">{{ job.createdAt | date: 'short' }}</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> </tr>
</ng-template> </ng-template>
<ng-template pTemplate="rowexpansion" let-job> <ng-template pTemplate="rowexpansion" let-job>
<tr> <tr>
<td colspan="4"> <td [attr.colspan]="getColspan()">
<pre>{{ [ <pre>{{ [
'Job: ' + job.id, 'Job: ' + job.id,
'Type: ' + job.type, 'Type: ' + job.type,
@ -67,12 +74,12 @@
</td> </td>
</tr> </tr>
<tr> <tr>
<td colspan="4"> <td [attr.colspan]="getColspan()">
<pre>{{ job.data }}</pre> <pre>{{ job.data }}</pre>
</td> </td>
</tr> </tr>
<tr class="job-error" *ngIf="job.error"> <tr class="job-error" *ngIf="job.error">
<td colspan="4"> <td [attr.colspan]="getColspan()">
<pre>{{ job.error }}</pre> <pre>{{ job.error }}</pre>
</td> </td>
</tr> </tr>
@ -80,11 +87,17 @@
<ng-template pTemplate="emptymessage"> <ng-template pTemplate="emptymessage">
<tr> <tr>
<td colspan="4"> <td [attr.colspan]="getColspan()">
<div class="no-results"> <div class="no-results">
<div class="d-block"> <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="jobState === 'all'">
<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="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>
</div> </div>
</td> </td>

View File

@ -16,7 +16,7 @@ export class JobsComponent extends RestTable implements OnInit {
private static LOCAL_STORAGE_STATE = 'jobs-list-state' private static LOCAL_STORAGE_STATE = 'jobs-list-state'
private static LOCAL_STORAGE_TYPE = 'jobs-list-type' private static LOCAL_STORAGE_TYPE = 'jobs-list-type'
jobState: JobStateClient = 'waiting' jobState?: JobStateClient | 'all'
jobStates: JobStateClient[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ] jobStates: JobStateClient[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ]
jobType: JobTypeClient = 'all' jobType: JobTypeClient = 'all'
@ -73,6 +73,10 @@ export class JobsComponent extends RestTable implements OnInit {
} }
} }
getColspan () {
return this.jobState === 'all' ? 5 : 4
}
onJobStateOrTypeChanged () { onJobStateOrTypeChanged () {
this.pagination.start = 0 this.pagination.start = 0
@ -81,8 +85,16 @@ export class JobsComponent extends RestTable implements OnInit {
} }
protected loadData () { protected loadData () {
let jobState = this.jobState as JobState
if (this.jobState === 'all') jobState = null
this.jobsService this.jobsService
.getJobs(this.jobState, this.jobType, this.pagination, this.sort) .getJobs({
jobState,
jobType: this.jobType,
pagination: this.pagination,
sort: this.sort
})
.subscribe( .subscribe(
resultList => { resultList => {
this.jobs = resultList.data this.jobs = resultList.data

View File

@ -12,11 +12,23 @@ import {
setDefaultSort setDefaultSort
} from '../../middlewares' } from '../../middlewares'
import { paginationValidator } from '../../middlewares/validators' 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 { isArray } from '../../helpers/custom-validators/misc'
import { jobStates } from '@server/helpers/custom-validators/jobs'
const jobsRouter = express.Router() const jobsRouter = express.Router()
jobsRouter.get('/',
authenticate,
ensureUserHasRight(UserRight.MANAGE_JOBS),
paginationValidator,
jobsSortValidator,
setDefaultSort,
setDefaultPagination,
listJobsValidator,
asyncMiddleware(listJobs)
)
jobsRouter.get('/:state', jobsRouter.get('/:state',
authenticate, authenticate,
ensureUserHasRight(UserRight.MANAGE_JOBS), ensureUserHasRight(UserRight.MANAGE_JOBS),
@ -25,6 +37,7 @@ jobsRouter.get('/:state',
setDefaultSort, setDefaultSort,
setDefaultPagination, setDefaultPagination,
listJobsValidator, listJobsValidator,
listJobsStateValidator,
asyncMiddleware(listJobs) asyncMiddleware(listJobs)
) )
@ -37,7 +50,7 @@ export {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
async function listJobs (req: express.Request, res: express.Response) { async function listJobs (req: express.Request, res: express.Response) {
const state = req.params.state as JobState const state = req.params.state as JobState || jobStates
const asc = req.query.sort === 'createdAt' const asc = req.query.sort === 'createdAt'
const jobType = req.query.jobType const jobType = req.query.jobType
@ -52,7 +65,11 @@ async function listJobs (req: express.Request, res: express.Response) {
const result: ResultList<Job> = { const result: ResultList<Job> = {
total, 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) return res.json(result)
} }

View File

@ -15,6 +15,7 @@ function isValidJobType (value: any) {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
export { export {
jobStates,
isValidJobState, isValidJobState,
isValidJobType isValidJobType
} }

View File

@ -154,13 +154,13 @@ class JobQueue {
} }
async listForApi (options: { async listForApi (options: {
state: JobState state: JobState | JobState[]
start: number start: number
count: number count: number
asc?: boolean asc?: boolean
jobType: JobType jobType: JobType
}): Promise<Bull.Job[]> { }): Promise<Bull.Job[]> {
const { state, start, count, asc, jobType } = options const { state = Array.isArray(options.state) ? options.state : [ options.state ], start, count, asc, jobType } = options
let results: Bull.Job[] = [] let results: Bull.Job[] = []
const filteredJobTypes = this.filterJobTypes(jobType) const filteredJobTypes = this.filterJobTypes(jobType)
@ -172,7 +172,7 @@ class JobQueue {
continue 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) results = results.concat(jobs)
} }
@ -188,7 +188,8 @@ class JobQueue {
return results.slice(start, start + count) 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 = 0 let total = 0
const filteredJobTypes = this.filterJobTypes(jobType) const filteredJobTypes = this.filterJobTypes(jobType)
@ -202,7 +203,9 @@ class JobQueue {
const counts = await queue.getJobCounts() const counts = await queue.getJobCounts()
total += counts[state] for (const s of states) {
total += counts[s]
}
} }
return total return total

View File

@ -5,8 +5,6 @@ import { logger } from '../../helpers/logger'
import { areValidationErrors } from './utils' import { areValidationErrors } from './utils'
const listJobsValidator = [ const listJobsValidator = [
param('state')
.custom(isValidJobState).not().isEmpty().withMessage('Should have a valid job state'),
query('jobType') query('jobType')
.optional() .optional()
.custom(isValidJobType).withMessage('Should have a valid job state'), .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 { export {
listJobsValidator listJobsValidator,
listJobsStateValidator
} }

View File

@ -356,15 +356,17 @@ paths:
- name: state - name: state
in: path in: path
required: true required: true
description: The state of the job description: The state of the job ('' for for no filter)
schema: schema:
type: string type: string
enum: enum:
- ''
- active - active
- completed - completed
- failed - failed
- waiting - waiting
- delayed - delayed
- $ref: '#/components/parameters/jobType'
- $ref: '#/components/parameters/start' - $ref: '#/components/parameters/start'
- $ref: '#/components/parameters/count' - $ref: '#/components/parameters/count'
- $ref: '#/components/parameters/sort' - $ref: '#/components/parameters/sort'
@ -3780,6 +3782,26 @@ components:
schema: schema:
type: string type: string
example: peertube-plugin-auth-ldap example: 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
- email
- video-transcoding
- video-file-import
- video-import
- videos-views
- activitypub-refresher
- video-redundancy
- video-live-ending
securitySchemes: securitySchemes:
OAuth2: OAuth2:
description: > description: >