1
+ import { MutationError , ErrorCodeEnum } from './../helpers/MutationError' ;
1
2
import { SchemaComposer , ObjectTypeComposerFieldConfigAsObjectDefinition } from 'graphql-compose' ;
3
+ import { findQueue } from '../helpers' ;
2
4
import { deleteQueue } from '../helpers' ;
3
5
import { Options } from '../definitions' ;
4
6
@@ -25,8 +27,34 @@ export function createQueueDeleteFC(
25
27
type : 'Boolean' ,
26
28
defaultValue : true ,
27
29
} ,
30
+ checkActivity : {
31
+ type : 'Boolean' ,
32
+ defaultValue : true ,
33
+ } ,
28
34
} ,
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
+ }
30
58
const total = await deleteQueue ( prefix , queueName , opts , checkExistence ) ;
31
59
return { total } ;
32
60
} ,
0 commit comments