1+ import { MutationError , ErrorCodeEnum } from './../helpers/MutationError' ;
12import { SchemaComposer , ObjectTypeComposerFieldConfigAsObjectDefinition } from 'graphql-compose' ;
3+ import { findQueue } from '../helpers' ;
24import { deleteQueue } from '../helpers' ;
35import { Options } from '../definitions' ;
46
@@ -25,8 +27,34 @@ export function createQueueDeleteFC(
2527 type : 'Boolean' ,
2628 defaultValue : true ,
2729 } ,
30+ checkActivity : {
31+ type : 'Boolean' ,
32+ defaultValue : true ,
33+ } ,
2834 } ,
29- resolve : async ( _ , { prefix, queueName, checkExistence } ) => {
35+ resolve : async ( _ , { prefix, queueName, checkExistence, checkActivity } ) => {
36+ if ( checkActivity ) {
37+ const queue = await findQueue ( prefix , queueName , opts ) ;
38+ const actives = await queue . getActiveCount ( ) ;
39+ const workers = ( await queue . getWorkers ( ) ) . length ;
40+
41+ const messages : string [ ] = [ ] ;
42+
43+ if ( actives > 0 ) {
44+ messages . push ( `Queue have ${ actives } active jobs.` ) ;
45+ }
46+
47+ if ( workers > 0 ) {
48+ messages . push ( `Queue have ${ workers } workers.` ) ;
49+ }
50+
51+ if ( messages . length > 0 ) {
52+ throw new MutationError (
53+ [ 'Queue is active!' , ...messages ] . join ( ' ' ) ,
54+ ErrorCodeEnum . OTHER_ERROR
55+ ) ;
56+ }
57+ }
3058 const total = await deleteQueue ( prefix , queueName , opts , checkExistence ) ;
3159 return { total } ;
3260 } ,
0 commit comments