Skip to content

Commit 28971c6

Browse files
authored
Add runtime options sample (#862)
1 parent 1060cfa commit 28971c6

File tree

7 files changed

+160
-0
lines changed

7 files changed

+160
-0
lines changed

lerna.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"quickstarts/big-ben/functions",
3434
"quickstarts/email-users/functions",
3535
"quickstarts/pubsub-helloworld/functions",
36+
"quickstarts/runtime-options/functions",
3637
"quickstarts/thumbnails/functions",
3738
"quickstarts/time-server/functions",
3839
"quickstarts/uppercase-firestore/functions",
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
firebase-debug.log*
8+
firebase-debug.*.log*
9+
10+
# Firebase cache
11+
.firebase/
12+
13+
# Firebase config
14+
15+
# Uncomment this if you'd like others to create their own Firebase project.
16+
# For a team working on the same Firebase project(s), it is recommended to leave
17+
# it commented so all members can deploy to the same project(s) in .firebaserc.
18+
# .firebaserc
19+
20+
# Runtime data
21+
pids
22+
*.pid
23+
*.seed
24+
*.pid.lock
25+
26+
# Directory for instrumented libs generated by jscoverage/JSCover
27+
lib-cov
28+
29+
# Coverage directory used by tools like istanbul
30+
coverage
31+
32+
# nyc test coverage
33+
.nyc_output
34+
35+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
36+
.grunt
37+
38+
# Bower dependency directory (https://bower.io/)
39+
bower_components
40+
41+
# node-waf configuration
42+
.lock-wscript
43+
44+
# Compiled binary addons (http://nodejs.org/api/addons.html)
45+
build/Release
46+
47+
# Dependency directories
48+
node_modules/
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Optional REPL history
57+
.node_repl_history
58+
59+
# Output of 'npm pack'
60+
*.tgz
61+
62+
# Yarn Integrity file
63+
.yarn-integrity
64+
65+
# dotenv environment variables file
66+
.env
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"functions": {
3+
"source": "functions",
4+
"predeploy": [
5+
"npm --prefix \"$RESOURCE_DIR\" run lint"
6+
]
7+
}
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
es6: true,
5+
node: true,
6+
},
7+
extends: [
8+
"eslint:recommended",
9+
"google",
10+
],
11+
rules: {
12+
quotes: ["error", "double"],
13+
},
14+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const functions = require("firebase-functions");
2+
3+
// [START runtimeMinInstances]
4+
exports.getAutocompleteResponse = functions
5+
.runWith(
6+
// Keep 5 instances warm for this latency-critical function
7+
{
8+
minInstances: 5,
9+
}
10+
)
11+
.https.onCall((data, context) => {
12+
// Autocomplete a user's search term
13+
});
14+
// [END runtimeMinInstances]
15+
16+
// [START runtimeMaxInstances]
17+
exports.mirrorOrdersToLegacyDatabase = functions
18+
.runWith(
19+
// Legacy database only supports 100 simultaneous connections
20+
{
21+
maxInstances: 100,
22+
}
23+
)
24+
.firestore.document("orders/{orderId}")
25+
.onWrite((change, context) => {
26+
// Connect to legacy database
27+
});
28+
// [END runtimeMaxInstances]
29+
30+
// [START runtimeTimeoutMemory]
31+
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+
)
40+
.storage.object()
41+
.onFinalize((object) => {
42+
// Do some complicated things that take a lot of memory and time
43+
});
44+
// [END runtimeTimeoutMemory]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "functions-runtime-options",
3+
"description": "Cloud Functions for Firebase",
4+
"scripts": {
5+
"lint": "eslint .",
6+
"serve": "firebase emulators:start --only functions",
7+
"shell": "firebase functions:shell",
8+
"start": "npm run shell",
9+
"deploy": "firebase deploy --only functions",
10+
"logs": "firebase functions:log"
11+
},
12+
"engines": {
13+
"node": "12"
14+
},
15+
"main": "index.js",
16+
"dependencies": {
17+
"firebase-admin": "^9.2.0",
18+
"firebase-functions": "^3.11.0"
19+
},
20+
"devDependencies": {
21+
"eslint": "^7.6.0",
22+
"eslint-config-google": "^0.14.0",
23+
"firebase-functions-test": "^0.2.0"
24+
},
25+
"private": true
26+
}

0 commit comments

Comments
 (0)