{"action":"created","comment":{"url":"https://api.github.com/repos/Unity-Technologies/katana/pulls/comments/53307667","id":53307667,"diff_hunk":"@@ -0,0 +1,148 @@\n+# This file is part of Buildbot.  Buildbot is free software: you can\n+# redistribute it and/or modify it under the terms of the GNU General Public\n+# License as published by the Free Software Foundation, version 2.\n+#\n+# This program is distributed in the hope that it will be useful, but WITHOUT\n+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more\n+# details.\n+#\n+# You should have received a copy of the GNU General Public License along with\n+# this program; if not, write to the Free Software Foundation, Inc., 51\n+# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n+#\n+# Copyright Buildbot Team Members\n+\n+\n+\"\"\"Push events to nats\n+\n+.\"\"\"\n+\n+from buildbot.status.status_push import StatusPush\n+from buildbot.status.persistent_queue import DiskQueue, MemoryQueue, PersistentQueue\n+from buildbot import config\n+\n+from twisted.python import log\n+import pynats\n+import urlparse\n+import json\n+\n+\n+class NatsStatusPush(StatusPush):\n+    \"\"\"Event streamer to a Nats server.\"\"\"\n+\n+    def __init__(self, serverUrl, subject=\"katana\", debug=None, maxMemoryItems=None,\n+                 maxDiskItems=None, chunkSize=200, maxPushSize=2 ** 20, extra_post_params=None, **kwargs):\n+        \"\"\"\n+        @serverUrl: The Nats server to be used to push events notifications to.\n+        @subject: The subject to use when publishing data\n+        @maxMemoryItems: Maximum number of items to keep queued in memory.\n+        @maxDiskItems: Maximum number of items to buffer to disk, if 0, doesn't\n+        use disk at all.\n+        @debug: Save the json with nice formatting.\n+        @chunkSize: maximum number of items to send in each at each PUSH.\n+        @maxPushSize: limits the size of encoded data for AE, the default\n+        is 1MB.\n+        \"\"\"\n+        if not serverUrl:\n+            raise config.ConfigErrors(['NatsStatusPush requires a serverUrl'])\n+\n+        # Parameters.\n+        self.serverUrl = serverUrl\n+        self.extra_post_params = extra_post_params or {}\n+        self.debug = debug\n+        self.chunkSize = chunkSize\n+        self.lastPushWasSuccessful = True\n+        self.subject = subject\n+        self.maxPushSize = maxPushSize\n+        self.c = None\n+\n+        if maxDiskItems != 0:\n+            # The queue directory is determined by the server url.\n+            path = ('events_' +\n+                    urlparse.urlparse(self.serverUrl)[1].split(':')[0])\n+            queue = PersistentQueue(\n+                        primaryQueue=MemoryQueue(maxItems=maxMemoryItems),\n+                        secondaryQueue=DiskQueue(path, maxItems=maxDiskItems))\n+        else:\n+            path = None\n+            queue = MemoryQueue(maxItems=maxMemoryItems)\n+\n+        # Use the unbounded method.\n+        StatusPush.__init__(self, serverPushCb=NatsStatusPush.pushData,\n+                            queue=queue, path=path, **kwargs)\n+\n+    def wasLastPushSuccessful(self):\n+        return self.lastPushWasSuccessful\n+\n+    def popChunk(self):\n+        \"\"\"Pops items from the pending list.\n+\n+        They must be queued back on failure.\"\"\"\n+        if self.wasLastPushSuccessful():\n+            chunkSize = self.chunkSize\n+        else:\n+            chunkSize = 1\n+\n+        while True:\n+            items = self.queue.popChunk(chunkSize)\n+            newitems = []\n+            for item in items:\n+                if hasattr(item, 'asDict'):\n+                    newitems.append(item.asDict())\n+                else:\n+                    newitems.append(item)\n+            if self.debug:\n+                packets = json.dumps(newitems, indent=2, sort_keys=True)\n+            else:\n+                packets = json.dumps(newitems, separators=(',', ':'))\n+\n+            data = packets","path":"master/buildbot/status/status_nats.py","position":99,"original_position":100,"commit_id":"db1bb2ba6b0f801054905910fcf101ebbad85559","original_commit_id":"52a3dfffa931f485ad85128d4c619eb89063c7c7","user":{"login":"campos-ddc","id":893630,"avatar_url":"https://avatars.githubusercontent.com/u/893630?v=3","gravatar_id":"","url":"https://api.github.com/users/campos-ddc","html_url":"https://github.com/campos-ddc","followers_url":"https://api.github.com/users/campos-ddc/followers","following_url":"https://api.github.com/users/campos-ddc/following{/other_user}","gists_url":"https://api.github.com/users/campos-ddc/gists{/gist_id}","starred_url":"https://api.github.com/users/campos-ddc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/campos-ddc/subscriptions","organizations_url":"https://api.github.com/users/campos-ddc/orgs","repos_url":"https://api.github.com/users/campos-ddc/repos","events_url":"https://api.github.com/users/campos-ddc/events{/privacy}","received_events_url":"https://api.github.com/users/campos-ddc/received_events","type":"User","site_admin":false},"body":"I would just use `packets` all the way","created_at":"2016-02-18T12:35:02Z","updated_at":"2016-02-18T12:35:02Z","html_url":"https://github.com/Unity-Technologies/katana/pull/138#discussion_r53307667","pull_request_url":"https://api.github.com/repos/Unity-Technologies/katana/pulls/138","_links":{"self":{"href":"https://api.github.com/repos/Unity-Technologies/katana/pulls/comments/53307667"},"html":{"href":"https://github.com/Unity-Technologies/katana/pull/138#discussion_r53307667"},"pull_request":{"href":"https://api.github.com/repos/Unity-Technologies/katana/pulls/138"}}},"pull_request":{"url":"https://api.github.com/repos/Unity-Technologies/katana/pulls/138","id":59790324,"html_url":"https://github.com/Unity-Technologies/katana/pull/138","diff_url":"https://github.com/Unity-Technologies/katana/pull/138.diff","patch_url":"https://github.com/Unity-Technologies/katana/pull/138.patch","issue_url":"https://api.github.com/repos/Unity-Technologies/katana/issues/138","number":138,"state":"open","locked":false,"title":"Added the ability to push data at a NATS Server","user":{"login":"opdude","id":312493,"avatar_url":"https://avatars.githubusercontent.com/u/312493?v=3","gravatar_id":"","url":"https://api.github.com/users/opdude","html_url":"https://github.com/opdude","followers_url":"https://api.github.com/users/opdude/followers","following_url":"https://api.github.com/users/opdude/following{/other_user}","gists_url":"https://api.github.com/users/opdude/gists{/gist_id}","starred_url":"https://api.github.com/users/opdude/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opdude/subscriptions","organizations_url":"https://api.github.com/users/opdude/orgs","repos_url":"https://api.github.com/users/opdude/repos","events_url":"https://api.github.com/users/opdude/events{/privacy}","received_events_url":"https://api.github.com/users/opdude/received_events","type":"User","site_admin":false},"body":"First pass to get feedback ASAP","created_at":"2016-02-18T12:14:51Z","updated_at":"2016-02-18T12:35:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"538a400e9bcf679ee9e51f63a5e633fd27e4ac01","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Unity-Technologies/katana/pulls/138/commits","review_comments_url":"https://api.github.com/repos/Unity-Technologies/katana/pulls/138/comments","review_comment_url":"https://api.github.com/repos/Unity-Technologies/katana/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Unity-Technologies/katana/issues/138/comments","statuses_url":"https://api.github.com/repos/Unity-Technologies/katana/statuses/db1bb2ba6b0f801054905910fcf101ebbad85559","head":{"label":"Unity-Technologies:feature/nats-io","ref":"feature/nats-io","sha":"db1bb2ba6b0f801054905910fcf101ebbad85559","user":{"login":"Unity-Technologies","id":426196,"avatar_url":"https://avatars.githubusercontent.com/u/426196?v=3","gravatar_id":"","url":"https://api.github.com/users/Unity-Technologies","html_url":"https://github.com/Unity-Technologies","followers_url":"https://api.github.com/users/Unity-Technologies/followers","following_url":"https://api.github.com/users/Unity-Technologies/following{/other_user}","gists_url":"https://api.github.com/users/Unity-Technologies/gists{/gist_id}","starred_url":"https://api.github.com/users/Unity-Technologies/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Unity-Technologies/subscriptions","organizations_url":"https://api.github.com/users/Unity-Technologies/orgs","repos_url":"https://api.github.com/users/Unity-Technologies/repos","events_url":"https://api.github.com/users/Unity-Technologies/events{/privacy}","received_events_url":"https://api.github.com/users/Unity-Technologies/received_events","type":"Organization","site_admin":false},"repo":{"id":8049051,"name":"katana","full_name":"Unity-Technologies/katana","owner":{"login":"Unity-Technologies","id":426196,"avatar_url":"https://avatars.githubusercontent.com/u/426196?v=3","gravatar_id":"","url":"https://api.github.com/users/Unity-Technologies","html_url":"https://github.com/Unity-Technologies","followers_url":"https://api.github.com/users/Unity-Technologies/followers","following_url":"https://api.github.com/users/Unity-Technologies/following{/other_user}","gists_url":"https://api.github.com/users/Unity-Technologies/gists{/gist_id}","starred_url":"https://api.github.com/users/Unity-Technologies/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Unity-Technologies/subscriptions","organizations_url":"https://api.github.com/users/Unity-Technologies/orgs","repos_url":"https://api.github.com/users/Unity-Technologies/repos","events_url":"https://api.github.com/users/Unity-Technologies/events{/privacy}","received_events_url":"https://api.github.com/users/Unity-Technologies/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Unity-Technologies/katana","description":"Unity's fork of Buildbot, a Python-based continuous integration testing framework!","fork":true,"url":"https://api.github.com/repos/Unity-Technologies/katana","forks_url":"https://api.github.com/repos/Unity-Technologies/katana/forks","keys_url":"https://api.github.com/repos/Unity-Technologies/katana/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Unity-Technologies/katana/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Unity-Technologies/katana/teams","hooks_url":"https://api.github.com/repos/Unity-Technologies/katana/hooks","issue_events_url":"https://api.github.com/repos/Unity-Technologies/katana/issues/events{/number}","events_url":"https://api.github.com/repos/Unity-Technologies/katana/events","assignees_url":"https://api.github.com/repos/Unity-Technologies/katana/assignees{/user}","branches_url":"https://api.github.com/repos/Unity-Technologies/katana/branches{/branch}","tags_url":"https://api.github.com/repos/Unity-Technologies/katana/tags","blobs_url":"https://api.github.com/repos/Unity-Technologies/katana/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Unity-Technologies/katana/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Unity-Technologies/katana/git/refs{/sha}","trees_url":"https://api.github.com/repos/Unity-Technologies/katana/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Unity-Technologies/katana/statuses/{sha}","languages_url":"https://api.github.com/repos/Unity-Technologies/katana/languages","stargazers_url":"https://api.github.com/repos/Unity-Technologies/katana/stargazers","contributors_url":"https://api.github.com/repos/Unity-Technologies/katana/contributors","subscribers_url":"https://api.github.com/repos/Unity-Technologies/katana/subscribers","subscription_url":"https://api.github.com/repos/Unity-Technologies/katana/subscription","commits_url":"https://api.github.com/repos/Unity-Technologies/katana/commits{/sha}","git_commits_url":"https://api.github.com/repos/Unity-Technologies/katana/git/commits{/sha}","comments_url":"https://api.github.com/repos/Unity-Technologies/katana/comments{/number}","issue_comment_url":"https://api.github.com/repos/Unity-Technologies/katana/issues/comments{/number}","contents_url":"https://api.github.com/repos/Unity-Technologies/katana/contents/{+path}","compare_url":"https://api.github.com/repos/Unity-Technologies/katana/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Unity-Technologies/katana/merges","archive_url":"https://api.github.com/repos/Unity-Technologies/katana/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Unity-Technologies/katana/downloads","issues_url":"https://api.github.com/repos/Unity-Technologies/katana/issues{/number}","pulls_url":"https://api.github.com/repos/Unity-Technologies/katana/pulls{/number}","milestones_url":"https://api.github.com/repos/Unity-Technologies/katana/milestones{/number}","notifications_url":"https://api.github.com/repos/Unity-Technologies/katana/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Unity-Technologies/katana/labels{/name}","releases_url":"https://api.github.com/repos/Unity-Technologies/katana/releases{/id}","deployments_url":"https://api.github.com/repos/Unity-Technologies/katana/deployments","created_at":"2013-02-06T10:22:01Z","updated_at":"2016-02-18T06:45:15Z","pushed_at":"2016-02-18T12:33:07Z","git_url":"git://github.com/Unity-Technologies/katana.git","ssh_url":"git@github.com:Unity-Technologies/katana.git","clone_url":"https://github.com/Unity-Technologies/katana.git","svn_url":"https://github.com/Unity-Technologies/katana","homepage":"","size":84161,"stargazers_count":69,"watchers_count":69,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":1,"forks":7,"open_issues":1,"watchers":69,"default_branch":"katana"}},"base":{"label":"Unity-Technologies:katana","ref":"katana","sha":"16533c48eeffc20759159a831c2cba65cfa776a2","user":{"login":"Unity-Technologies","id":426196,"avatar_url":"https://avatars.githubusercontent.com/u/426196?v=3","gravatar_id":"","url":"https://api.github.com/users/Unity-Technologies","html_url":"https://github.com/Unity-Technologies","followers_url":"https://api.github.com/users/Unity-Technologies/followers","following_url":"https://api.github.com/users/Unity-Technologies/following{/other_user}","gists_url":"https://api.github.com/users/Unity-Technologies/gists{/gist_id}","starred_url":"https://api.github.com/users/Unity-Technologies/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Unity-Technologies/subscriptions","organizations_url":"https://api.github.com/users/Unity-Technologies/orgs","repos_url":"https://api.github.com/users/Unity-Technologies/repos","events_url":"https://api.github.com/users/Unity-Technologies/events{/privacy}","received_events_url":"https://api.github.com/users/Unity-Technologies/received_events","type":"Organization","site_admin":false},"repo":{"id":8049051,"name":"katana","full_name":"Unity-Technologies/katana","owner":{"login":"Unity-Technologies","id":426196,"avatar_url":"https://avatars.githubusercontent.com/u/426196?v=3","gravatar_id":"","url":"https://api.github.com/users/Unity-Technologies","html_url":"https://github.com/Unity-Technologies","followers_url":"https://api.github.com/users/Unity-Technologies/followers","following_url":"https://api.github.com/users/Unity-Technologies/following{/other_user}","gists_url":"https://api.github.com/users/Unity-Technologies/gists{/gist_id}","starred_url":"https://api.github.com/users/Unity-Technologies/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Unity-Technologies/subscriptions","organizations_url":"https://api.github.com/users/Unity-Technologies/orgs","repos_url":"https://api.github.com/users/Unity-Technologies/repos","events_url":"https://api.github.com/users/Unity-Technologies/events{/privacy}","received_events_url":"https://api.github.com/users/Unity-Technologies/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Unity-Technologies/katana","description":"Unity's fork of Buildbot, a Python-based continuous integration testing framework!","fork":true,"url":"https://api.github.com/repos/Unity-Technologies/katana","forks_url":"https://api.github.com/repos/Unity-Technologies/katana/forks","keys_url":"https://api.github.com/repos/Unity-Technologies/katana/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Unity-Technologies/katana/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Unity-Technologies/katana/teams","hooks_url":"https://api.github.com/repos/Unity-Technologies/katana/hooks","issue_events_url":"https://api.github.com/repos/Unity-Technologies/katana/issues/events{/number}","events_url":"https://api.github.com/repos/Unity-Technologies/katana/events","assignees_url":"https://api.github.com/repos/Unity-Technologies/katana/assignees{/user}","branches_url":"https://api.github.com/repos/Unity-Technologies/katana/branches{/branch}","tags_url":"https://api.github.com/repos/Unity-Technologies/katana/tags","blobs_url":"https://api.github.com/repos/Unity-Technologies/katana/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Unity-Technologies/katana/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Unity-Technologies/katana/git/refs{/sha}","trees_url":"https://api.github.com/repos/Unity-Technologies/katana/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Unity-Technologies/katana/statuses/{sha}","languages_url":"https://api.github.com/repos/Unity-Technologies/katana/languages","stargazers_url":"https://api.github.com/repos/Unity-Technologies/katana/stargazers","contributors_url":"https://api.github.com/repos/Unity-Technologies/katana/contributors","subscribers_url":"https://api.github.com/repos/Unity-Technologies/katana/subscribers","subscription_url":"https://api.github.com/repos/Unity-Technologies/katana/subscription","commits_url":"https://api.github.com/repos/Unity-Technologies/katana/commits{/sha}","git_commits_url":"https://api.github.com/repos/Unity-Technologies/katana/git/commits{/sha}","comments_url":"https://api.github.com/repos/Unity-Technologies/katana/comments{/number}","issue_comment_url":"https://api.github.com/repos/Unity-Technologies/katana/issues/comments{/number}","contents_url":"https://api.github.com/repos/Unity-Technologies/katana/contents/{+path}","compare_url":"https://api.github.com/repos/Unity-Technologies/katana/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Unity-Technologies/katana/merges","archive_url":"https://api.github.com/repos/Unity-Technologies/katana/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Unity-Technologies/katana/downloads","issues_url":"https://api.github.com/repos/Unity-Technologies/katana/issues{/number}","pulls_url":"https://api.github.com/repos/Unity-Technologies/katana/pulls{/number}","milestones_url":"https://api.github.com/repos/Unity-Technologies/katana/milestones{/number}","notifications_url":"https://api.github.com/repos/Unity-Technologies/katana/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Unity-Technologies/katana/labels{/name}","releases_url":"https://api.github.com/repos/Unity-Technologies/katana/releases{/id}","deployments_url":"https://api.github.com/repos/Unity-Technologies/katana/deployments","created_at":"2013-02-06T10:22:01Z","updated_at":"2016-02-18T06:45:15Z","pushed_at":"2016-02-18T12:33:07Z","git_url":"git://github.com/Unity-Technologies/katana.git","ssh_url":"git@github.com:Unity-Technologies/katana.git","clone_url":"https://github.com/Unity-Technologies/katana.git","svn_url":"https://github.com/Unity-Technologies/katana","homepage":"","size":84161,"stargazers_count":69,"watchers_count":69,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":1,"forks":7,"open_issues":1,"watchers":69,"default_branch":"katana"}},"_links":{"self":{"href":"https://api.github.com/repos/Unity-Technologies/katana/pulls/138"},"html":{"href":"https://github.com/Unity-Technologies/katana/pull/138"},"issue":{"href":"https://api.github.com/repos/Unity-Technologies/katana/issues/138"},"comments":{"href":"https://api.github.com/repos/Unity-Technologies/katana/issues/138/comments"},"review_comments":{"href":"https://api.github.com/repos/Unity-Technologies/katana/pulls/138/comments"},"review_comment":{"href":"https://api.github.com/repos/Unity-Technologies/katana/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Unity-Technologies/katana/pulls/138/commits"},"statuses":{"href":"https://api.github.com/repos/Unity-Technologies/katana/statuses/db1bb2ba6b0f801054905910fcf101ebbad85559"}}}}