File tree 4 files changed +41
-1
lines changed
4 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 1
1
ACCESS_TOKEN =
2
- GITHUB_WEBHOOK_SECRET =
2
+ GITHUB_WEBHOOK_SECRET =
3
+ VERIFY_GITHUB_USER_AND_FETCH_SSH_KEYS_URL =
Original file line number Diff line number Diff line change @@ -5,12 +5,16 @@ const admin = require("firebase-admin");
5
5
const {
6
6
onRequest,
7
7
} = require ( "firebase-functions/v2/https" ) ;
8
+ const {
9
+ onSchedule,
10
+ } = require ( "firebase-functions/v2/scheduler" ) ;
8
11
9
12
admin . initializeApp ( ) ;
10
13
11
14
const handleGitHubStarsWebhookFunction = require ( "./src/handleGitHubStarsWebhook.js" ) ;
12
15
const handleGitHubSponsorsWebhookFunction = require ( "./src/handleGitHubSponsorsWebhook.js" ) ;
13
16
const verifyGitHubUserAndFetchSSHKeysFunction = require ( "./src/verifyGitHubUserAndFetchSSHKeys.js" ) ;
17
+ const warmerFunction = require ( "./src/warmer.js" ) ;
14
18
15
19
exports . handleGitHubStarsWebhook = onRequest ( {
16
20
region : "europe-west9" ,
@@ -30,3 +34,9 @@ exports.verifyGitHubUserAndFetchSSHKeysFunction = onRequest({
30
34
verifyGitHubUserAndFetchSSHKeysFunction . verifyGitHubUserAndFetchSSHKeys ( req , res ) ;
31
35
} ) ) ;
32
36
37
+ exports . warmer = onSchedule ( {
38
+ region : "europe-west3" ,
39
+ schedule : "* * * * *" ,
40
+ } , async ( event ) => {
41
+ warmerFunction . warmer ( event ) ;
42
+ } ) ;
Original file line number Diff line number Diff line change @@ -10,6 +10,11 @@ const {
10
10
const logger = require ( "firebase-functions/logger" ) ;
11
11
12
12
exports . verifyGitHubUserAndFetchSSHKeys = async ( req , res ) => {
13
+ if ( req . query . isWarming === "true" ) {
14
+ logger . info ( "Warming request handled successfully" ) ;
15
+ return res . status ( 200 ) . send ( "Warming request handled successfully" ) ;
16
+ }
17
+
13
18
const username = req . query . username ;
14
19
15
20
try {
Original file line number Diff line number Diff line change
1
+ const axios = require ( "axios" ) ;
2
+
3
+ const functionUrls = [
4
+ process . env . VERIFY_GITHUB_USER_AND_FETCH_SSH_KEYS_URL ,
5
+ ] ;
6
+
7
+ exports . warmer = async ( ) => {
8
+ console . log ( "Starting to warm up functions..." ) ;
9
+ for ( const url of functionUrls ) {
10
+ try {
11
+ const response = await axios . get ( url , {
12
+ headers : {
13
+ Authorization : process . env . ACCESS_TOKEN ,
14
+ } ,
15
+ params : {
16
+ isWarming : "true" ,
17
+ } ,
18
+ } ) ;
19
+ console . log ( `Warming up ${ url } : Success with status ${ response . status } ` ) ;
20
+ } catch ( error ) {
21
+ console . error ( `Error warming up ${ url } : ${ error . message } ` ) ;
22
+ }
23
+ }
24
+ } ;
You can’t perform that action at this time.
0 commit comments