@@ -2,25 +2,36 @@ const functions = require("firebase-functions");
2
2
3
3
// [START runtimeMinInstances]
4
4
exports . getAutocompleteResponse = functions
5
- . runWith (
6
- // Keep 5 instances warm for this latency-critical function
7
- {
8
- minInstances : 5 ,
9
- }
10
- )
5
+ . runWith ( {
6
+ // Keep 5 instances warm for this latency-critical function
7
+ minInstances : 5 ,
8
+ } )
11
9
. https . onCall ( ( data , context ) => {
12
10
// Autocomplete a user's search term
13
11
} ) ;
14
12
// [END runtimeMinInstances]
15
13
14
+ // [START runtimeMinInstancesDynamic]
15
+ // Get Firebase project id from `FIREBASE_CONFIG` environment variable
16
+ const envProjectId = JSON . parse ( process . env . FIREBASE_CONFIG ) . projectId ;
17
+
18
+ exports . renderProfilePage = functions
19
+ . runWith ( {
20
+ // Keep 5 instances warm for this latency-critical function
21
+ // in production only. Default to 0 for test projects.
22
+ minInstances : envProjectId === "my-production-project" ? 5 : 0 ,
23
+ } )
24
+ . https . onRequest ( ( req , res ) => {
25
+ // render some html
26
+ } ) ;
27
+ // [END runtimeMinInstancesDynamic]
28
+
16
29
// [START runtimeMaxInstances]
17
30
exports . mirrorOrdersToLegacyDatabase = functions
18
- . runWith (
19
- // Legacy database only supports 100 simultaneous connections
20
- {
21
- maxInstances : 100 ,
22
- }
23
- )
31
+ . runWith ( {
32
+ // Legacy database only supports 100 simultaneous connections
33
+ maxInstances : 100 ,
34
+ } )
24
35
. firestore . document ( "orders/{orderId}" )
25
36
. onWrite ( ( change , context ) => {
26
37
// Connect to legacy database
@@ -29,14 +40,12 @@ exports.mirrorOrdersToLegacyDatabase = functions
29
40
30
41
// [START runtimeTimeoutMemory]
31
42
exports . convertLargeFile = functions
32
- . runWith (
33
- // Ensure the function has enough memory and time
34
- // to process large files
35
- {
36
- timeoutSeconds : 300 ,
37
- memory : "1GB" ,
38
- }
39
- )
43
+ . runWith ( {
44
+ // Ensure the function has enough memory and time
45
+ // to process large files
46
+ timeoutSeconds : 300 ,
47
+ memory : "1GB" ,
48
+ } )
40
49
. storage . object ( )
41
50
. onFinalize ( ( object ) => {
42
51
// Do some complicated things that take a lot of memory and time
0 commit comments