Created
December 8, 2015 11:29
-
-
Save jgeewax/12816b5c4a5ce4218ff1 to your computer and use it in GitHub Desktop.
gcloud-node-pubsub-topic-bug
This file contains 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
node_modules |
This file contains 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
example output (note the incorrect URL in the response body): | |
delme_704317 created | |
attempting to delete topic projects/projectname/topics/delme_704317 | |
Error deleting topic! | |
<!DOCTYPE html> | |
<html lang=en> | |
<meta charset=utf-8> | |
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width"> | |
<title>Error 404 (Not Found)!!1</title> | |
<style> | |
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px} | |
</style> | |
<a href=//www.google.com/><span id=logo aria-label=Google></span></a> | |
<p><b>404.</b> <ins>That’s an error.</ins> | |
<p>The requested URL <code>/v1/projects/projectname/topics/projects/projectname/topics/delme_704317</code> was not found on this server. <ins>That’s all we know.</ins> | |
/mydir/gcloud-node-pubsub-topic-bug/index.js:49 | |
throw err3; | |
^ | |
ApiError: Not Found | |
at new util.ApiError (/mydir/gcloud-node-pubsub-topic-bug/node_modules/gcloud/lib/common/util.js:92:10) | |
at Object.parseHttpRespMessage (/mydir/gcloud-node-pubsub-topic-bug/node_modules/gcloud/lib/common/util.js:134:33) | |
at Object.handleResp (/mydir/gcloud-node-pubsub-topic-bug/node_modules/gcloud/lib/common/util.js:109:18) | |
at /mydir/gcloud-node-pubsub-topic-bug/node_modules/gcloud/lib/common/util.js:411:12 | |
at Request.onResponse [as _callback] (/mydir/gcloud-node-pubsub-topic-bug/node_modules/retry-request/index.js:113:7) | |
at Request.self.callback (/mydir/gcloud-node-pubsub-topic-bug/node_modules/request/request.js:198:22) | |
at emitTwo (events.js:87:13) | |
at Request.emit (events.js:172:7) | |
at Request.<anonymous> (/mydir/gcloud-node-pubsub-topic-bug/node_modules/request/request.js:1035:10) | |
at emitOne (events.js:82:20) |
This file contains 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
"use strict"; | |
var _Gcloud = require('gcloud'); | |
var _Ram = require('ramda'); | |
//workaround for errors not propagating from async await | |
process.on('unhandledRejection', err => { throw err; }); | |
function getRandomInt(min, max) { | |
return Math.floor(Math.random() * (max - min)) + min; | |
} | |
function shouldDeleteTopic(topic) { | |
var regex = new RegExp('^delme_'); | |
let t_title = topic.name.split('/').pop(); | |
return t_title.match(regex); | |
} | |
var pubsub = _Gcloud.pubsub({ keyFilename: process.env.GCLOUD_AUTH_FILE });; | |
let topic_name='delme_' + getRandomInt(1,999999); | |
pubsub.createTopic(topic_name, function(err1, apiResponse1) { | |
if (err1) { | |
throw err1; | |
} | |
console.log(topic_name + ' created'); | |
pubsub.getTopics({pageSize: 50}, function (err2, topics, nextQuery, apiResponse2) { | |
if (err2) { | |
console.log('Error getting topics'); | |
throw err2; | |
} | |
var topics_to_delete = _Ram.filter(shouldDeleteTopic, topics); | |
var topic_to_delete = topics_to_delete.pop(); | |
console.log('attempting to delete topic ' + topic_to_delete.name); | |
topic_to_delete.delete(function (err3, apiResponse3) { | |
if (err3) { | |
console.error('Error deleting topic!'); | |
console.log(apiResponse3); | |
throw err3; | |
} | |
console.log('topic deleted with response'); | |
console.log(apiResponse3); | |
}); | |
}); | |
}); |
This file contains 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
{ | |
name: "gcloud-node-pubsub-topic-bug", | |
version: "0.0.1", | |
description: "", | |
main: "index.js", | |
scripts: { | |
test: "echo "Error: no test specified" && exit 1" | |
}, | |
author: "Chris Hiestand <chris@oakleon.com>", | |
license: "ISC", | |
dependencies: { | |
gcloud: "^0.26.0", | |
ramda: "^0.18.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment