- Notifications
You must be signed in to change notification settings - Fork 642
Implement settable timeouts in Functions. #224
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits Select commit Hold shift + click to select a range
9715b32
Implement settable timeouts in Functions.
bklimt 2968d8d
add a newline
bklimt 137a727
add copyright header
bklimt 24ee595
Fix the test javascript.
bklimt 3ab5a4f
style fixes
bklimt 4496521
Up the default timeout to 70s.
bklimt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions 46 firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallOptions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2018 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
| ||
package com.google.firebase.functions; | ||
| ||
import java.util.concurrent.TimeUnit; | ||
import okhttp3.OkHttpClient; | ||
| ||
/** An internal class for keeping track of options applied to an HttpsCallableReference. */ | ||
class HttpsCallOptions { | ||
bklimt marked this conversation as resolved. Show resolved Hide resolved | ||
| ||
// The default timeout to use for all calls. | ||
private static final long DEFAULT_TIMEOUT = 70; | ||
private static final TimeUnit DEFAULT_TIMEOUT_UNITS = TimeUnit.SECONDS; | ||
| ||
// The timeout to use for calls from references created by this Functions. | ||
private long timeout = DEFAULT_TIMEOUT; | ||
private TimeUnit timeoutUnits = DEFAULT_TIMEOUT_UNITS; | ||
| ||
/** | ||
* Changes the timeout for calls from this instance of Functions. The default is 60 seconds. | ||
* | ||
* @param timeout The length of the timeout, in the given units. | ||
* @param units The units for the specified timeout. | ||
*/ | ||
void setTimeout(long timeout, TimeUnit units) { | ||
this.timeout = timeout; | ||
this.timeoutUnits = units; | ||
} | ||
| ||
/** Creates a new OkHttpClient with these options applied to it. */ | ||
OkHttpClient apply(OkHttpClient client) { | ||
return client.newBuilder().callTimeout(timeout, timeoutUnits).build(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
| @@ -16,15 +16,20 @@ | |
| ||
import android.support.annotation.Nullable; | ||
import com.google.android.gms.tasks.Task; | ||
import java.util.concurrent.TimeUnit; | ||
| ||
/** A reference to a particular Callable HTTPS trigger in Cloud Functions. */ | ||
public class HttpsCallableReference { | ||
| ||
// The functions client to use for making calls. | ||
private final FirebaseFunctions functionsClient; | ||
| ||
// The name of the HTTPS endpoint this reference refers to. | ||
private final String name; | ||
| ||
// Options for how to do the HTTPS call. | ||
HttpsCallOptions options = new HttpsCallOptions(); | ||
| ||
/** Creates a new reference with the given options. */ | ||
HttpsCallableReference(FirebaseFunctions functionsClient, String name) { | ||
this.functionsClient = functionsClient; | ||
| @@ -71,7 +76,7 @@ public class HttpsCallableReference { | |
* @see FirebaseFunctionsException | ||
*/ | ||
public Task<HttpsCallableResult> call(@Nullable Object data) { | ||
return functionsClient.call(name, data); | ||
return functionsClient.call(name, data, options); | ||
} | ||
| ||
/** | ||
| @@ -89,6 +94,28 @@ public Task<HttpsCallableResult> call(@Nullable Object data) { | |
* @return A Task that will be completed when the HTTPS request has completed. | ||
*/ | ||
public Task<HttpsCallableResult> call() { | ||
return functionsClient.call(name, null); | ||
return functionsClient.call(name, null, options); | ||
} | ||
| ||
/** | ||
* Changes the timeout for calls from this instance of Functions. The default is 60 seconds. | ||
* | ||
* @param timeout The length of the timeout, in the given units. | ||
* @param units The units for the specified timeout. | ||
*/ | ||
public void setTimeout(long timeout, TimeUnit units) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this require an API review? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the API has been approved. go/callable-timeouts | ||
options.setTimeout(timeout, units); | ||
} | ||
| ||
/** | ||
* Creates a new reference with the given timeout for calls. The default is 60 seconds. | ||
* | ||
* @param timeout The length of the timeout, in the given units. | ||
* @param units The units for the specified timeout. | ||
*/ | ||
public HttpsCallableReference withTimeout(long timeout, TimeUnit units) { | ||
HttpsCallableReference other = new HttpsCallableReference(functionsClient, name); | ||
other.setTimeout(timeout, units); | ||
return other; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.