18
18
* Background Cloud Function that only executes within a certain time
19
19
* period after the triggering event to avoid infinite retry loops.
20
20
*
21
- * @param {object } event The Cloud Functions event payload.
22
- * @param {function } context Information about the event.
21
+ * @param {object } data The event payload.
22
+ * @param {object } context The event metadata .
23
23
*/
24
24
exports . avoidInfiniteRetries = ( data , context ) => {
25
25
const eventAge = Date . now ( ) - Date . parse ( context . timestamp ) ;
@@ -41,8 +41,8 @@ exports.avoidInfiniteRetries = (data, context) => {
41
41
* Background Cloud Function that demonstrates
42
42
* how to toggle retries using a promise
43
43
*
44
- * @param {object } data The Cloud Functions event payload.
45
- * @param {function } context The Cloud Functions metadata.
44
+ * @param {object } data The event payload.
45
+ * @param {object } context The event metadata.
46
46
*/
47
47
exports . retryPromise = ( data , context ) => {
48
48
const tryAgain = ! ! data . retry ;
@@ -59,9 +59,10 @@ exports.retryPromise = (data, context) => {
59
59
/**
60
60
* Background Cloud Function.
61
61
*
62
- * @param {object } data Data passed to the Cloud Function.
62
+ * @param {object } data The event payload.
63
+ * @param {object } context The event metadata.
63
64
*/
64
- exports . helloBackground = ( data ) => {
65
+ exports . helloBackground = ( data , context ) => {
65
66
return `Hello ${ data . name || 'World' } !` ;
66
67
} ;
67
68
// [END functions_helloworld_background_node8]
@@ -72,11 +73,12 @@ exports.helloBackground = (data) => {
72
73
* This function is exported by index.js, and executed when
73
74
* the trigger topic receives a message.
74
75
*
75
- * @param {object } data The Cloud Functions event payload.
76
- * @param {object } context The Cloud Functions metadata.
76
+ * @param {object } data The event payload.
77
+ * @param {object } context The event metadata.
77
78
*/
78
- exports . helloPubSub = ( data ) => {
79
- const name = data . data ? Buffer . from ( data . data , 'base64' ) . toString ( ) : 'World' ;
79
+ exports . helloPubSub = ( data , context ) => {
80
+ const pubSubMessage = data ;
81
+ const name = pubSubMessage . data ? Buffer . from ( pubSubMessage . data , 'base64' ) . toString ( ) : 'World' ;
80
82
81
83
console . log ( `Hello, ${ name } !` ) ;
82
84
} ;
@@ -86,17 +88,19 @@ exports.helloPubSub = (data) => {
86
88
/**
87
89
* Background Cloud Function to be triggered by Cloud Storage.
88
90
*
89
- * @param {object } data The Cloud Functions event payload.
91
+ * @param {object } data The event payload.
92
+ * @param {object } context The event metadata.
90
93
*/
91
- exports . helloGCS = ( data ) => {
92
- if ( data . resourceState === 'not_exists' ) {
93
- console . log ( `File ${ data . name } deleted.` ) ;
94
- } else if ( data . metageneration === '1' ) {
94
+ exports . helloGCS = ( data , context ) => {
95
+ const file = data ;
96
+ if ( file . resourceState === 'not_exists' ) {
97
+ console . log ( `File ${ file . name } deleted.` ) ;
98
+ } else if ( file . metageneration === '1' ) {
95
99
// metageneration attribute is updated on metadata changes.
96
100
// on create value is 1
97
- console . log ( `File ${ data . name } uploaded.` ) ;
101
+ console . log ( `File ${ file . name } uploaded.` ) ;
98
102
} else {
99
- console . log ( `File ${ data . name } metadata updated.` ) ;
103
+ console . log ( `File ${ file . name } metadata updated.` ) ;
100
104
}
101
105
} ;
102
106
// [END functions_helloworld_storage_node8]
@@ -105,16 +109,17 @@ exports.helloGCS = (data) => {
105
109
/**
106
110
* Generic background Cloud Function to be triggered by Cloud Storage.
107
111
*
108
- * @param {object } data The Cloud Functions event payload.
109
- * @param {object } context The Cloud Functions event metadata.
112
+ * @param {object } data The event payload.
113
+ * @param {object } context The event metadata.
110
114
*/
111
115
exports . helloGCSGeneric = ( data , context ) => {
116
+ const file = data ;
112
117
console . log ( ` Event ${ context . eventId } ` ) ;
113
118
console . log ( ` Event Type: ${ context . eventType } ` ) ;
114
- console . log ( ` Bucket: ${ data . bucket } ` ) ;
115
- console . log ( ` File: ${ data . name } ` ) ;
116
- console . log ( ` Metageneration: ${ data . metageneration } ` ) ;
117
- console . log ( ` Created: ${ data . timeCreated } ` ) ;
118
- console . log ( ` Updated: ${ data . updated } ` ) ;
119
+ console . log ( ` Bucket: ${ file . bucket } ` ) ;
120
+ console . log ( ` File: ${ file . name } ` ) ;
121
+ console . log ( ` Metageneration: ${ file . metageneration } ` ) ;
122
+ console . log ( ` Created: ${ file . timeCreated } ` ) ;
123
+ console . log ( ` Updated: ${ file . updated } ` ) ;
119
124
} ;
120
125
// [END functions_helloworld_storage_generic_node8]
0 commit comments