Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update retry samples #677

Merged
merged 2 commits into from
Jul 23, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update retry samples
  • Loading branch information
Ace Nassri authored Jun 27, 2018
commit 69ed966c27a522f956c3a4d7ddc2922b9bd8be6d
8 changes: 4 additions & 4 deletions functions/tips/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ exports.avoidInfiniteRetries = (event, callback) => {
};
// [END functions_tips_infinite_retries]

// [START functions_tips_retry_promise]
/**
* Background Cloud Function that demonstrates
* how to toggle retries using a promise
Expand All @@ -172,15 +171,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 +193,16 @@ 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]

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