2025-08-08 15:56:37 -04:00
import { Body , Controller , Get , HttpCode , HttpStatus , Param , Post , Put } from '@nestjs/common' ;
2025-11-13 08:18:43 -05:00
import { ApiTags } from '@nestjs/swagger' ;
import { Endpoint , HistoryBuilder } from 'src/decorators' ;
2025-11-25 08:19:40 -05:00
import { AuthDto } from 'src/dtos/auth.dto' ;
2025-11-14 14:42:00 -05:00
import { JobCreateDto } from 'src/dtos/job.dto' ;
2025-11-25 08:19:40 -05:00
import { QueueResponseLegacyDto , QueuesResponseLegacyDto } from 'src/dtos/queue-legacy.dto' ;
import { QueueCommandDto , QueueNameParamDto } from 'src/dtos/queue.dto' ;
2025-11-11 17:01:14 -05:00
import { ApiTag , Permission } from 'src/enum' ;
2025-11-25 08:19:40 -05:00
import { Auth , Authenticated } from 'src/middleware/auth.guard' ;
2024-03-21 00:07:30 +01:00
import { JobService } from 'src/services/job.service' ;
2025-11-14 14:42:00 -05:00
import { QueueService } from 'src/services/queue.service' ;
2023-03-20 11:55:28 -04:00
2025-11-11 17:01:14 -05:00
@ApiTags ( ApiTag . Jobs )
2023-03-20 11:55:28 -04:00
@Controller ( 'jobs' )
export class JobController {
2025-11-14 14:42:00 -05:00
constructor (
private service : JobService ,
private queueService : QueueService ,
) { }
2023-03-20 11:55:28 -04:00
@Get ( )
2025-07-25 15:25:23 -04:00
@Authenticated ( { permission : Permission.JobRead , admin : true } )
2025-11-13 08:18:43 -05:00
@Endpoint ( {
2025-11-11 17:01:14 -05:00
summary : 'Retrieve queue counts and status' ,
description : 'Retrieve the counts of the current queue, as well as the current status.' ,
2025-11-25 08:19:40 -05:00
history : new HistoryBuilder ( ) . added ( 'v1' ) . beta ( 'v1' ) . stable ( 'v2' ) . deprecated ( 'v2.4.0' ) ,
2025-11-11 17:01:14 -05:00
} )
2025-11-25 08:19:40 -05:00
getQueuesLegacy ( @Auth ( ) auth : AuthDto ) : Promise < QueuesResponseLegacyDto > {
return this . queueService . getAllLegacy ( auth ) ;
2023-03-20 11:55:28 -04:00
}
2024-09-16 16:49:12 -04:00
@Post ( )
2025-07-25 15:25:23 -04:00
@Authenticated ( { permission : Permission.JobCreate , admin : true } )
2025-08-08 15:56:37 -04:00
@HttpCode ( HttpStatus . NO_CONTENT )
2025-11-13 08:18:43 -05:00
@Endpoint ( {
2025-11-11 17:01:14 -05:00
summary : 'Create a manual job' ,
description :
'Run a specific job. Most jobs are queued automatically, but this endpoint allows for manual creation of a handful of jobs, including various cleanup tasks, as well as creating a new database backup.' ,
2025-11-13 08:18:43 -05:00
history : new HistoryBuilder ( ) . added ( 'v1' ) . beta ( 'v1' ) . stable ( 'v2' ) ,
2025-11-11 17:01:14 -05:00
} )
2024-09-16 16:49:12 -04:00
createJob ( @Body ( ) dto : JobCreateDto ) : Promise < void > {
return this . service . create ( dto ) ;
}
2025-11-14 14:42:00 -05:00
@Put ( ':name' )
2025-07-25 15:25:23 -04:00
@Authenticated ( { permission : Permission.JobCreate , admin : true } )
2025-11-13 08:18:43 -05:00
@Endpoint ( {
2025-11-11 17:01:14 -05:00
summary : 'Run jobs' ,
description :
'Queue all assets for a specific job type. Defaults to only queueing assets that have not yet been processed, but the force command can be used to re-process all assets.' ,
2025-11-25 08:19:40 -05:00
history : new HistoryBuilder ( ) . added ( 'v1' ) . beta ( 'v1' ) . stable ( 'v2' ) . deprecated ( 'v2.4.0' ) ,
2025-11-11 17:01:14 -05:00
} )
2025-11-25 08:19:40 -05:00
runQueueCommandLegacy (
@Param ( ) { name } : QueueNameParamDto ,
@Body ( ) dto : QueueCommandDto ,
) : Promise < QueueResponseLegacyDto > {
return this . queueService . runCommandLegacy ( name , dto ) ;
2023-03-20 11:55:28 -04:00
}
}