-
Notifications
You must be signed in to change notification settings - Fork 598
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
Move subscription methods up a level #618
Move subscription methods up a level #618
Conversation
* | ||
* @throws {Error} If a name is not provided. | ||
* | ||
* @param {string} name - The name of the subscription. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Different than what I had in mind. I was thinking more like: // topic is in options
pubsub.subscribe('my-sub', { topic: pubsub.topic('some-topic') }, callback); Thinking now, Here's a partial attempt I made a while ago: https://github.com/ryanseys/gcloud-node/commit/78c4cfe6b06a7dcc1d44e226b00dbbc51a31d096 don't let it confuse you because it's not complete but something to gander at. |
I'm just getting the topic name ( Quick API comparison :) // ---
// This PR:
// ---
var pubsub = gcloud.pubsub({ projectId: 'grape-spaceship-123' });
// Each of these next two lines do the same thing:
pubsub.topic('some-topic').subscribe('my-sub', callback);
pubsub.subscribe('some-topic', 'new-sub-name', callback);
// Subscribe to a topic from another project.
pubsub.subscribe('another-topic', 'another-new-sub-name', { projectId: 'squishy-butter-334' }, callback);
// ---
// Your Idea:
// ---
var pubsub = gcloud.pubsub({ projectId: 'grape-spaceship-123' });
// Each of these next two lines do the same thing:
pubsub.topic('some-topic').subscribe('my-sub', callback);
pubsub.subscribe('new-sub-name', pubsub.topic('some-topic'), callback);
// Subscribe to a topic from another project.
var anotherPubsub = gcloud.pubsub({ projectId: 'squishy-butter-334' });
pubsub.subscribe('another-new-sub-name', anotherPubsub.topic('another-topic'), callback); The main difference is requiring a Topic object vs. using explicit string params. I like both. Halp. |
Couldn't we take bits of both? var pubsub1 = gcloud.pubsub({ projectId: 'project1' });
// These all do the same thing
pubsub1.topic('some-topic').subscribe('my-sub', callback); // Most common pattern
pubsub1.subscribe('new-sub-name', 'some-topic', callback); // Uncommon, but just a name implies same project
pubsub1.subscribe('new-sub-name', pubsub1.topic('some-topic'), callback); // Uncommon, most explicit.
// So then, if we want to subscribe to a topic in another project,
// the only way to do that is to create a topic object that knows it's project.
var pubsub2 = gcloud.pubsub({ projectId: 'project2' });
pubsub2.subscribe('new-sub-name', pubsub1.topic('some-topic'), callback); |
I'm cool with that. Now just one smaller detail; shouldn't topic name come before subscription? pubsub.subscribe('new-sub-name', 'some-topic', callback);
// vs.
pubsub.subscribe('some-topic', 'new-sub-name', callback); I like the latter, just to follow the standard hierarchy "project -> topic -> subscription". Just for completeness, here's the full sig: pubsub.subscribe( ( Topic('topic-name') || 'topic-name' ), 'sub-name', [{ autoAck: true, ... }], function(err, subscription, apiResponse) {}); |
SGTM. Since topic is absolutely required, it should definitely be first. |
Aren't both topic and sub-name required? Either order makes sense to me, so whatever you like :) |
Yea, both required -- topic being higher up in the hierarchy seems like it should come first though. Sorry, didn't articulate that piece too. :P |
Cool SGTM! |
1a12ede
to
82d316b
Compare
PTAL. |
@@ -163,6 +163,123 @@ PubSub.prototype.createTopic = function(name, callback) { | |||
}; | |||
|
|||
/** | |||
* Create a subscription to this topic. You may optionally provide an object to |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
6c95ee7
to
08ed5d4
Compare
3c59635
to
a4e3243
Compare
While Travis takes a year to run this build... I'm not sure how I can write a system test for this functionality, since we only have access to one project. Unit testing covers all of the changes pretty well, since it was mostly just relocating code. To support subscribing from another project, all we're really doing is passing a different topic string to the API. The unit tests cover that as well. Is that enough? |
I think this should be good. I can go ahead with a code review if you're ready? |
Yes, please! |
|
||
options = options || {}; | ||
|
||
if (util.is(topic, 'string')) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
a4e3243
to
0669289
Compare
@@ -124,7 +124,7 @@ util.arrayize = arrayize; | |||
*/ | |||
function format(template, args) { | |||
return template.replace(/{([^}]*)}/g, function(match, key) { | |||
return args[key] || match; | |||
return key in args ? args[key] : match; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Merge time! |
Move subscription methods up a level
#618) * build(node): add feat in node post-processor to add client library version number in snippet metadata Co-authored-by: Benjamin E. Coe <[email protected]> Source-Link: googleapis/synthtool@d337b88 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-nodejs:latest@sha256:d106724ad2a96daa1b8d88de101ba50bdb30b8df62ffa0aa2b451d93b4556641
#618) * build(node): add feat in node post-processor to add client library version number in snippet metadata Co-authored-by: Benjamin E. Coe <[email protected]> Source-Link: googleapis/synthtool@d337b88 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-nodejs:latest@sha256:d106724ad2a96daa1b8d88de101ba50bdb30b8df62ffa0aa2b451d93b4556641
#618) * build(node): add feat in node post-processor to add client library version number in snippet metadata Co-authored-by: Benjamin E. Coe <[email protected]> Source-Link: googleapis/synthtool@d337b88 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-nodejs:latest@sha256:d106724ad2a96daa1b8d88de101ba50bdb30b8df62ffa0aa2b451d93b4556641
🤖 I have created a release \*beep\* \*boop\* --- ### [3.4.1](https://www.github.com/googleapis/nodejs-video-intelligence/compare/v3.4.0...v3.4.1) (2021-09-15) ### Bug Fixes * **deps:** require google-gax v2.24.1 ([#589](https://www.github.com/googleapis/nodejs-video-intelligence/issues/589)) ([6af1a84](https://www.github.com/googleapis/nodejs-video-intelligence/commit/6af1a84112ab56a3ff2862ff7a5eda0da9772244)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
🤖 I have created a release \*beep\* \*boop\* --- ### [3.4.1](https://www.github.com/googleapis/nodejs-video-intelligence/compare/v3.4.0...v3.4.1) (2021-09-15) ### Bug Fixes * **deps:** require google-gax v2.24.1 ([#589](https://www.github.com/googleapis/nodejs-video-intelligence/issues/589)) ([6af1a84](https://www.github.com/googleapis/nodejs-video-intelligence/commit/6af1a84112ab56a3ff2862ff7a5eda0da9772244)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
This PR was generated using Autosynth. 🌈 Synth log will be available here: https://source.cloud.google.com/results/invocations/1bcecc39-aa5c-40f4-9453-955704c7ca01/targets - [ ] To automatically regenerate this PR, check this box. Source-Link: googleapis/synthtool@57c23fa
- [ ] Regenerate this pull request now. PiperOrigin-RevId: 468790263 Source-Link: googleapis/googleapis@873ab45 Source-Link: googleapis/googleapis-gen@cb6f37a Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiY2I2ZjM3YWVmZjJhMzQ3MmU0MGE3YmJhY2U4YzY3ZDc1ZTI0YmVlNSJ9
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
#618) * build(node): add feat in node post-processor to add client library version number in snippet metadata Co-authored-by: Benjamin E. Coe <[email protected]> Source-Link: googleapis/synthtool@d337b88 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-nodejs:latest@sha256:d106724ad2a96daa1b8d88de101ba50bdb30b8df62ffa0aa2b451d93b4556641
* feat: support regapic LRO Use gapic-generator-typescript v2.15.1. PiperOrigin-RevId: 456946341 Source-Link: googleapis/googleapis@88fd18d Source-Link: googleapis/googleapis-gen@accfa37 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYWNjZmEzNzFmNjY3NDM5MzEzMzM1YzY0MDQyYjA2M2MxYzUzMTAyZSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Fixes #605