@@ -6,6 +6,7 @@ import { createServiceLogger } from '../../utils/logging'
66import SequelizeRepository from '../../database/repositories/sequelizeRepository'
77import { sendNodeWorkerMessage } from '../../serverless/utils/nodeWorkerSQS'
88import { NodeWorkerIntegrationProcessMessage } from '../../types/mq/nodeWorkerIntegrationProcessMessage'
9+ import IntegrationRepository from '../../database/repositories/integrationRepository'
910
1011const banner = fs . readFileSync ( path . join ( __dirname , 'banner.txt' ) , 'utf8' )
1112
@@ -27,6 +28,11 @@ const options = [
2728 type : Boolean ,
2829 defaultValue : false ,
2930 } ,
31+ {
32+ name : 'platform' ,
33+ alias : 'p' ,
34+ description : 'The platform for which we should run all integrations.' ,
35+ } ,
3036 {
3137 name : 'help' ,
3238 alias : 'h' ,
@@ -52,24 +58,18 @@ const sections = [
5258const usage = commandLineUsage ( sections )
5359const parameters = commandLineArgs ( options )
5460
55- if ( parameters . help || ! parameters . integration ) {
61+ if ( parameters . help || ( ! parameters . integration && ! parameters . platform ) ) {
5662 console . log ( usage )
5763} else {
5864 setImmediate ( async ( ) => {
59- const integrationIds = parameters . integration . split ( ',' )
6065 const onboarding = parameters . onboarding
6166 const options = await SequelizeRepository . getDefaultIRepositoryOptions ( )
6267
63- for ( const integrationId of integrationIds ) {
64- const integration = await options . database . integration . findOne ( {
65- where : { id : integrationId } ,
66- } )
67-
68- if ( ! integration ) {
69- log . error ( { integrationId } , 'Integration not found!' )
70- process . exit ( 1 )
71- } else {
72- log . info ( { integrationId, onboarding } , 'Integration found - triggering SQS message!' )
68+ if ( parameters . platform ) {
69+ const integrations = await IntegrationRepository . findAllActive ( parameters . platform )
70+ for ( const i of integrations ) {
71+ const integration = i as any
72+ log . info ( { integrationId : integration . id , onboarding } , 'Triggering SQS message!' )
7373 await sendNodeWorkerMessage (
7474 integration . tenantId ,
7575 new NodeWorkerIntegrationProcessMessage (
@@ -80,7 +80,31 @@ if (parameters.help || !parameters.integration) {
8080 ) ,
8181 )
8282 }
83+ } else {
84+ const integrationIds = parameters . integration . split ( ',' )
85+ for ( const integrationId of integrationIds ) {
86+ const integration = await options . database . integration . findOne ( {
87+ where : { id : integrationId } ,
88+ } )
89+
90+ if ( ! integration ) {
91+ log . error ( { integrationId } , 'Integration not found!' )
92+ process . exit ( 1 )
93+ } else {
94+ log . info ( { integrationId, onboarding } , 'Integration found - triggering SQS message!' )
95+ await sendNodeWorkerMessage (
96+ integration . tenantId ,
97+ new NodeWorkerIntegrationProcessMessage (
98+ integration . platform ,
99+ integration . tenantId ,
100+ onboarding ,
101+ integration . id ,
102+ ) ,
103+ )
104+ }
105+ }
83106 }
107+
84108 process . exit ( 0 )
85109 } )
86110}
0 commit comments