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

pubsub: allow setting a pull HTTP timeout #981

Merged

Conversation

stephenplusplus
Copy link
Contributor

Fixes #980

What I would like to do is be able to send a timeout param in the pull request to tell subpub to send back a response after a 30000ms if no messages are published during that time.

We can't control the server's timeout setting through the API, but I tried to effectively recreate it. The user can cancel an outstanding pull request by breaking the HTTP connection. So this PR lets them set a timeout on the HTTP request. When that amount of time is reached, the request will be broken.

If we don't get a response from the server in that amount of time, we handle the "ETIMEDOUT" error by assuming because we haven't heard anything, there aren't any messages to return. Thus, we return an empty array of messages to the user.

@stephenplusplus stephenplusplus added the api: pubsub Issues related to the Pub/Sub API. label Nov 30, 2015
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 30, 2015
@stephenplusplus stephenplusplus force-pushed the spp--pubsub-timeout branch 2 times, most recently from b9deb2f to 3ed23db Compare November 30, 2015 20:47
this.maxInProgress =
is.number(options.maxInProgress) ? options.maxInProgress : Infinity;
this.messageListeners = 0;
this.paused = false;
this.timeout = options.timeout;

This comment was marked as spam.

This comment was marked as spam.

@stephenplusplus
Copy link
Contributor Author

@callmehiphop @mattraby -- I updated the PR. See the opening post for details. Let me know what you think!

@stephenplusplus
Copy link
Contributor Author

@tmatsuo read over the issue #980 and the originating StackOverflow issue that inspired this PR -- is this a good idea or not so much? Thanks!

@callmehiphop
Copy link
Contributor

With the addition of #979, is this still necessary?

@stephenplusplus
Copy link
Contributor Author

If we consider this feature useful (still TBD -- need help with that decision), then I think we're just making it easy with this. It would be a bit awkward for the user to do it themselves.

@callmehiphop
Copy link
Contributor

It sounds like we can't resolve the original issue via the client, however imo this is still a nice feature and it's one that could potentially benefit all of the other services.

@stephenplusplus
Copy link
Contributor Author

Oh, gotcha. Supporting easily configurable timeouts is a good idea and request interceptors would be the right way to do that on a global basis. But I still consider that an advanced need and a bit of a learning curve to understand how to do it with our library. In this case, only the HTTP ':pull' request should be affected, so I could see both making sense.

Related: #446 (comment)

@stephenplusplus stephenplusplus force-pushed the spp--pubsub-timeout branch 2 times, most recently from 46de268 to c540b31 Compare December 3, 2015 20:26
@stephenplusplus
Copy link
Contributor Author

@jgeewax @tmatsuo what do you think about this PR?

* @param {string} options.encoding - When pulling for messages, this type is
* used when converting a message's data to a string. (default: 'utf-8')
* @param {number} options.interval - Interval in milliseconds to check for new
* messages.
* messages. (default: 10)
* @param {number} options.maxInProgress - Maximum messages to consume

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@tmatsuo
Copy link
Contributor

tmatsuo commented Dec 7, 2015

@stephenplusplus The PR makes sense to me.

@stephenplusplus
Copy link
Contributor Author

@tmatsuo @jgeewax Thanks for the review!

@tmatsuo
Copy link
Contributor

tmatsuo commented Dec 7, 2015

LGTM

stephenplusplus added a commit that referenced this pull request Dec 7, 2015
pubsub: allow setting a pull HTTP timeout
@stephenplusplus stephenplusplus merged commit 8d6d661 into googleapis:master Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the Pub/Sub API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants