File tree Expand file tree Collapse file tree
services/apps/nango_worker/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -49,32 +49,38 @@ async function getLastConnectTs(): Promise<Date | undefined> {
4949export async function numberOfGithubConnectionsToCreate ( ) : Promise < number > {
5050 const max = Number ( process . env . CROWD_MAX_GH_NANGO_CONNECTIONS_PER_HOUR || 1 )
5151
52+ svc . log . info ( `[GITHUB] Max number of github connections to create: ${ max } ` )
53+
5254 if ( IS_DEV_ENV || IS_STAGING_ENV ) {
53- svc . log . info ( 'Number of github connections to create: 5' )
55+ svc . log . info ( '[GITHUB] Number of github connections to create: 5' )
5456 return 5
5557 }
5658
5759 const lastConnectDate = await getLastConnectTs ( )
5860
61+ svc . log . info ( `[GITHUB] Last connect date: ${ lastConnectDate . toISOString ( ) } ` )
62+
5963 if ( ! lastConnectDate ) {
60- svc . log . info ( `Number of github connections to create: ${ max } ` )
64+ svc . log . info ( `[GITHUB] Number of github connections to create: ${ max } ` )
6165 return max
6266 }
6367
64- // we can allow max 10 per day so every 120 minutes (2 hours) we can connect 1
6568 const now = new Date ( )
69+ svc . log . info ( `[GITHUB] Now: ${ now . toISOString ( ) } ` )
6670
6771 // time is milliseconds
6872 const diff = now . getTime ( ) - lastConnectDate . getTime ( )
6973
7074 // how many hours
7175 const hours = diff / ( 1000 * 60 * 60 ) // ms to seconds to minutes
76+ svc . log . info ( `[GITHUB] Diff: ${ diff } , hours: ${ hours } ` )
77+
7278 if ( hours >= 1.0 ) {
73- svc . log . info ( `Number of github connections to create: ${ max } ` )
79+ svc . log . info ( `[GITHUB] Number of github connections to create: ${ max } ` )
7480 return max
7581 }
7682
77- svc . log . info ( 'Number of github connections to create: 0' )
83+ svc . log . info ( '[GITHUB] Number of github connections to create: 0' )
7884 return 0
7985}
8086
Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ const activity = proxyActivities<typeof activities>({
88} )
99
1010export async function syncGithubIntegration ( args : ISyncGithubIntegrationArguments ) : Promise < void > {
11+ const limit = await activity . numberOfGithubConnectionsToCreate ( )
12+ let created = 0
13+
1114 for ( const integrationId of args . integrationIds ) {
1215 const result = await activity . analyzeGithubIntegration ( integrationId )
1316
@@ -24,8 +27,6 @@ export async function syncGithubIntegration(args: ISyncGithubIntegrationArgument
2427 }
2528
2629 // create connections for repos that are not already connected
27- const limit = await activity . numberOfGithubConnectionsToCreate ( )
28- let created = 0
2930 for ( const repo of result . reposToSync ) {
3031 if ( created >= limit ) {
3132 break
You can’t perform that action at this time.
0 commit comments