From 402145b8630d1908c35f8c22846ddc4475f25d3e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 14 Dec 2020 12:00:35 +0100 Subject: Refactor jobs state --- shared/extra-utils/server/jobs.ts | 20 ++++++++++++++------ shared/models/server/job.model.ts | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'shared') diff --git a/shared/extra-utils/server/jobs.ts b/shared/extra-utils/server/jobs.ts index cac00e9ab..a53749589 100644 --- a/shared/extra-utils/server/jobs.ts +++ b/shared/extra-utils/server/jobs.ts @@ -1,12 +1,20 @@ import * as request from 'supertest' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' +import { makeGetRequest } from '../../../shared/extra-utils' import { Job, JobState, JobType } from '../../models' import { wait } from '../miscs/miscs' import { ServerInfo } from './servers' -import { makeGetRequest } from '../../../shared/extra-utils' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' -function getJobsList (url: string, accessToken: string, state: JobState) { - const path = '/api/v1/jobs/' + state +function buildJobsUrl (state?: JobState) { + let path = '/api/v1/jobs' + + if (state) path += '/' + state + + return path +} + +function getJobsList (url: string, accessToken: string, state?: JobState) { + const path = buildJobsUrl(state) return request(url) .get(path) @@ -19,14 +27,14 @@ function getJobsList (url: string, accessToken: string, state: JobState) { function getJobsListPaginationAndSort (options: { url: string accessToken: string - state: JobState start: number count: number sort: string + state?: JobState jobType?: JobType }) { const { url, accessToken, state, start, count, sort, jobType } = options - const path = '/api/v1/jobs/' + state + const path = buildJobsUrl(state) const query = { start, diff --git a/shared/models/server/job.model.ts b/shared/models/server/job.model.ts index 346b25607..b0ed860a7 100644 --- a/shared/models/server/job.model.ts +++ b/shared/models/server/job.model.ts @@ -2,7 +2,7 @@ import { ContextType } from '../activitypub/context' import { VideoResolution } from '../videos/video-resolution.enum' import { SendEmailOptions } from './emailer.model' -export type JobState = 'active' | 'completed' | 'failed' | 'waiting' | 'delayed' +export type JobState = 'active' | 'completed' | 'failed' | 'waiting' | 'delayed' | 'paused' export type JobType = | 'activitypub-http-unicast' -- cgit v1.2.3