@@ -18,20 +18,20 @@ public class GetReadmeFunction
1818 readonly CloudQueueClient _cloudQueueClient ;
1919 readonly GitHubRestApiService _gitHubRestApiService ;
2020 readonly GitHubGraphQLApiService _gitHubGraphQLApiService ;
21- readonly GitHubApiExceptionService _gitHubApiExceptionService ;
21+ readonly GitHubApiStatusService _gitHubApiStatusService ;
2222
2323 public GetReadmeFunction ( CloudQueueClient cloudQueueClient ,
2424 IHttpClientFactory httpClientFactory ,
2525 GitHubRestApiService gitHubApiService ,
26- GitHubGraphQLApiService gitHubGraphQLApiService ,
27- GitHubApiExceptionService gitHubApiExceptionService )
26+ GitHubApiStatusService gitHubApiStatusService ,
27+ GitHubGraphQLApiService gitHubGraphQLApiService )
2828 {
2929 _httpClient = httpClientFactory . CreateClient ( ) ;
3030
3131 _cloudQueueClient = cloudQueueClient ;
3232 _gitHubRestApiService = gitHubApiService ;
33+ _gitHubApiStatusService = gitHubApiStatusService ;
3334 _gitHubGraphQLApiService = gitHubGraphQLApiService ;
34- _gitHubApiExceptionService = gitHubApiExceptionService ;
3535 }
3636
3737 [ FunctionName ( nameof ( GetReadmeQueueTriggerFunction ) ) ]
@@ -41,52 +41,39 @@ public async Task GetReadmeQueueTriggerFunction([QueueTrigger(QueueConstants.Rep
4141 {
4242 const int minimumApiRequests = 2000 ;
4343
44- int gitHubRestApiRequestsRemaining , gitHubGraphQLApiRequestsRemaining ;
45-
4644 log . LogInformation ( $ "{ nameof ( GetReadmeFunction ) } Stared") ;
4745
4846 var ( repository , gitHubUser ) = data ;
4947
50- try
51- {
52- var restApiResponse = await _gitHubRestApiService . GetResponseMessage ( ) . ConfigureAwait ( false ) ;
53- var graphQLApiResponse = await _gitHubGraphQLApiService . GetViewerInformation ( ) . ConfigureAwait ( false ) ;
48+ var ( gitHubRestApiRequestsRemaining , gitHubGraphQLApiRequestsRemaining ) = await _gitHubApiStatusService . GetRemaininRequestCount ( ) . ConfigureAwait ( false ) ;
5449
55- gitHubRestApiRequestsRemaining = _gitHubApiExceptionService . GetRemainingRequestCount ( restApiResponse . Headers ) ;
56- gitHubGraphQLApiRequestsRemaining = _gitHubApiExceptionService . GetRemainingRequestCount ( graphQLApiResponse . Headers ) ;
57- }
58- catch ( Exception e ) when ( _gitHubApiExceptionService . HasReachedMaximimApiCallLimit ( e ) )
59- {
60- gitHubRestApiRequestsRemaining = gitHubGraphQLApiRequestsRemaining = 0 ;
61- }
62-
6350 log . LogInformation ( $ "{ nameof ( gitHubRestApiRequestsRemaining ) } : { gitHubRestApiRequestsRemaining } ") ;
64- log . LogInformation ( $ "{ nameof ( gitHubGraphQLApiRequestsRemaining ) } : { gitHubGraphQLApiRequestsRemaining } ") ;
65-
66- try
51+ log . LogInformation ( $ "{ nameof ( gitHubGraphQLApiRequestsRemaining ) } : { gitHubGraphQLApiRequestsRemaining } ") ;
52+
53+
54+ // The GitHub API Limits requests to 5,0000 per hour https://docs.github.com/en/free-pro-team@latest/rest#rate-limiting
55+ // If the API Limit is approaching, output to RemainingRepositoriesQueue, where it will be handled by GetReadmeTimerTriggerFunction which runs once an hour
56+ // Otherwise, process the data and place it on VerifyWebTrendsQueue
57+ if ( gitHubRestApiRequestsRemaining < minimumApiRequests
58+ || gitHubGraphQLApiRequestsRemaining < minimumApiRequests )
6759 {
68-
69- // The GitHub API Limits requests to 5,0000 per hour https://docs.github.com/en/free-pro-team@latest/rest#rate-limiting
70- // If the API Limit is approaching, output to RemainingRepositoriesQueue, where it will be handled by GetReadmeTimerTriggerFunction which runs once an hour
71- // Otherwise, process the data and place it on VerifyWebTrendsQueue
72- if ( gitHubRestApiRequestsRemaining < minimumApiRequests
73- || gitHubGraphQLApiRequestsRemaining < minimumApiRequests )
74- {
75- log . LogInformation ( $ "Maximum API Requests Reached") ;
76-
77- remainingRepositoriesData . Add ( data ) ;
78-
79- log . LogInformation ( $ "Added Data to RemainingRepositoriesQueue") ;
80- }
81- else
82- {
83- await RetrieveReadme ( repository , gitHubUser , log , completedRepositoriesData ) . ConfigureAwait ( false ) ;
84- }
60+ log . LogInformation ( $ "Maximum API Requests Reached") ;
61+
62+ remainingRepositoriesData . Add ( data ) ;
63+
64+ log . LogInformation ( $ "Added Data to RemainingRepositoriesQueue") ;
8565 }
86- catch ( Refit . ApiException e ) when ( e . StatusCode is System . Net . HttpStatusCode . NotFound )
66+ else
8767 {
88- //If a Readme doesn't exist, GitHubApiService.GetReadme will return a 404 Not Found response
89- }
68+ try
69+ {
70+ await RetrieveReadme ( repository , gitHubUser , log , completedRepositoriesData ) . ConfigureAwait ( false ) ;
71+ }
72+ catch ( Refit . ApiException e ) when ( e . StatusCode is System . Net . HttpStatusCode . NotFound )
73+ {
74+ //If a Readme doesn't exist, GitHubApiService.GetReadme will return a 404 Not Found response
75+ }
76+ }
9077
9178 log . LogInformation ( $ "{ nameof ( GetReadmeFunction ) } Completed") ;
9279 }
@@ -116,9 +103,10 @@ public async Task GetReadmeTimerTriggerFunction([TimerTrigger(_runEveryHour, Run
116103
117104 try
118105 {
119- var response = await _gitHubRestApiService . GetResponseMessage ( ) . ConfigureAwait ( false ) ;
106+ var ( gitHubRestApiRequestsRemaining , gitHubGraphQLApiRequestsRemaining ) = await _gitHubApiStatusService . GetRemaininRequestCount ( ) . ConfigureAwait ( false ) ;
120107
121- if ( GitHubApiExceptionService . GetNumberOfApiRequestsRemaining ( response . Headers ) >= 2000 )
108+ if ( gitHubRestApiRequestsRemaining > 2000
109+ && gitHubGraphQLApiRequestsRemaining > 2000 )
122110 {
123111 await RetrieveReadme ( repository , gitHubUser , log , completedRepositoriesData ) . ConfigureAwait ( false ) ;
124112 await remainingRepositoriesQueue . DeleteMessageAsync ( queueMessage ) . ConfigureAwait ( false ) ;
0 commit comments