Skip to content

Commit 27e9150

Browse files
authored
Merge pull request #864 from firebase/jhuleatt-dynamic-config
Update runtime options sample
2 parents a3928fe + b175701 commit 27e9150

File tree

1 file changed

+29
-20
lines changed
  • quickstarts/runtime-options/functions

1 file changed

+29
-20
lines changed

quickstarts/runtime-options/functions/index.js

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,36 @@ const functions = require("firebase-functions");
22

33
// [START runtimeMinInstances]
44
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+
})
119
.https.onCall((data, context) => {
1210
// Autocomplete a user's search term
1311
});
1412
// [END runtimeMinInstances]
1513

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+
1629
// [START runtimeMaxInstances]
1730
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+
})
2435
.firestore.document("orders/{orderId}")
2536
.onWrite((change, context) => {
2637
// Connect to legacy database
@@ -29,14 +40,12 @@ exports.mirrorOrdersToLegacyDatabase = functions
2940

3041
// [START runtimeTimeoutMemory]
3142
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+
})
4049
.storage.object()
4150
.onFinalize((object) => {
4251
// Do some complicated things that take a lot of memory and time

0 commit comments

Comments
 (0)