Skip to content

Commit

Permalink
Update retry samples (#677)
Browse files Browse the repository at this point in the history
* Update retry samples

* Add region tags
  • Loading branch information
Ace Nassri authored Jul 23, 2018
1 parent d16994f commit dccf48a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions functions/tips/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ exports.avoidInfiniteRetries = (event, callback) => {
};
// [END functions_tips_infinite_retries]

// [START functions_tips_retry_promise]
// [START functions_tips_retry]
/**
* Background Cloud Function that demonstrates
* how to toggle retries using a promise
Expand All @@ -172,15 +172,15 @@ exports.avoidInfiniteRetries = (event, callback) => {
exports.retryPromise = (event) => {
const tryAgain = !!event.data.retry;

// [START functions_tips_retry_promise]
if (tryAgain) {
throw new Error(`Retrying...`);
} else {
return Promise.reject(new Error('Not retrying...'));
}
// [END functions_tips_retry_promise]
};
// [END functions_tips_retry_promise]

// [START functions_tips_retry_callback]
/**
* Background Cloud Function that demonstrates
* how to toggle retries using a callback
Expand All @@ -194,15 +194,17 @@ exports.retryCallback = (event, callback) => {
const tryAgain = !!event.data.retry;
const err = new Error('Error!');

// [START functions_tips_retry_callback]
if (tryAgain) {
console.error('Retrying:', err);
callback(err);
} else {
console.error('Not retrying:', err);
callback();
}
// [END functions_tips_retry_callback]
};
// [END functions_tips_retry_callback]
// [END functions_tips_retry]

// [START functions_tips_gcp_apis]
const Pubsub = require('@google-cloud/pubsub');
Expand Down

0 comments on commit dccf48a

Please sign in to comment.