11import { Config } from 'aws-sdk/lib/config'
22import GLUE from 'aws-sdk/clients/glue'
3- import { groupBy } from 'lodash'
3+ import { groupBy , isEmpty } from 'lodash'
44import { convertToPromise , fetchAllPaginatedData } from '../../utils/fetchUtils'
55import { initTestEndpoint } from '../../utils'
66import ErrorLog from '../../utils/errorLog'
@@ -23,29 +23,31 @@ export default async ({
2323} : {
2424 regions : string
2525 config : Config
26- } ) : Promise < { [ region : string ] : RawAwsGlueJob [ ] } > => {
26+ } ) : Promise < { [ region : string ] : RawAwsGlueJob [ ] } > => {
2727 const result : RawAwsGlueJob [ ] = [ ]
2828
2929 const activeRegions = regions . split ( ',' )
3030
3131 for ( const region of activeRegions ) {
32- let glueJobData : GLUE . Job [ ]
32+ let glueJobData : GLUE . Job [ ] = [ ]
3333 try {
34- glueJobData = await fetchAllPaginatedData ( {
35- getResourcesFn : convertToPromise ( {
36- sdkContext : new GLUE ( { ...config , region, endpoint } ) ,
37- fnName : 'getJobs' ,
38- } ) ,
39- accessor : '' ,
40- } ) ?? [ ]
34+ glueJobData =
35+ ( await fetchAllPaginatedData ( {
36+ getResourcesFn : convertToPromise ( {
37+ sdkContext : new GLUE ( { ...config , region, endpoint } ) ,
38+ fnName : 'getJobs' ,
39+ } ) ,
40+ accessor : '' ,
41+ } ) ) ?? [ ]
4142 } catch ( err ) {
4243 errorLog . generateAwsErrorLog ( {
4344 functionName : 'glueJob:getJobs' ,
44- err
45+ err,
4546 } )
4647 }
4748
48- result . push ( ...glueJobData . map ( val => ( { ...val , region } ) ) )
49+ if ( ! isEmpty ( glueJobData ) )
50+ result . push ( ...glueJobData . map ( val => ( { ...val , region } ) ) )
4951 }
5052 errorLog . reset ( )
5153 return groupBy ( result , 'region' )
0 commit comments