Skip to content
Snippets Groups Projects
Commit d1ac054d authored by Tianyi Liang's avatar Tianyi Liang
Browse files

[SD-235] job state

parent e96155b2
No related branches found
No related tags found
1 merge request!562Resolve SD-235 "Feat/ booth screen video"
import { Controller, Param, Post } from '@nestjs/common'
import { Controller, Get, Param, Post } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { Job } from 'bull'
import { ActivityLogEvent } from 'modules/activity-log/enums/activity-log-event.enum'
......@@ -42,4 +42,22 @@ export class VideosController {
event: ActivityLogEvent.TEAM_BOOTH_VIDEO_GENERATE,
})
}
@Get('jobs/:jobID')
@AssertStaffPrivilege(StaffPrivilegeKind.CAN_MANAGE_TEAMS)
async getJob(@Param('jobID') jobID: string): Promise<Job | null> {
return await this.jobQueue.fetchJob(jobID)
}
@Get('jobs/state/:jobID')
@AssertStaffPrivilege(StaffPrivilegeKind.CAN_MANAGE_TEAMS)
async getJobState(@Param('jobID') jobID: string): Promise<string> {
return (await this.jobQueue.fetchJobState(jobID)) as string
}
@Post('jobs/remove/:jobID')
@AssertStaffPrivilege(StaffPrivilegeKind.CAN_MANAGE_TEAMS)
async removeJob(@Param('jobID') jobID: string): Promise<void> {
await this.jobQueue.removeJob(jobID)
}
}
import { InjectQueue, Process, Processor } from '@nestjs/bull'
import { Inject, forwardRef } from '@nestjs/common'
import { Job, Queue } from 'bull'
import { Job, JobStatus, Queue } from 'bull'
import { JobQueue } from 'lib/job-queue/job-queue.enum'
import { VideosJobTypeEnum } from 'modules/videos/enums/videos-job-type.enum'
import { BatchProcessVideosJobPayload } from 'modules/videos/job-payloads/batch-process-videos.job-payload'
......@@ -91,4 +91,22 @@ export class VideosJobQueue {
job.data.event,
)
}
async fetchJob(jobId: string): Promise<Job | null> {
return await this.queue.getJob(jobId)
}
async fetchJobState(jobId: string): Promise<JobStatus | 'stuck' | undefined> {
const job = await this.queue.getJob(jobId)
if (job != null) {
return await job.getState()
}
}
async removeJob(jobId: string): Promise<void> {
const job = await this.queue.getJob(jobId)
if (job != null) {
await job.remove()
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment