{"action":"created","comment":{"url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments/196117685","pull_request_review_id":129610503,"id":196117685,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5NjExNzY4NQ==","diff_hunk":"@@ -100,29 +100,94 @@ def run(self):\n         self.process_changes(since=self.get_last_checkpoint_sequence(), forever=True)\n \n     def _update_checkpoint(self, change, context):\n-        if change:\n+        if change and context:\n             updated = self.fire_change_processed_event(change, context)\n         else:\n             updated = self.checkpoint.touch(min_interval=CHECKPOINT_MIN_WAIT)\n         if updated:\n             self._record_checkpoint_in_datadog()\n \n+    @property\n+    def _should_process_in_chunks(self):\n+        # chunked processing is only supported for pillows with single processor\n+        return (len(self.processors) == 1\n+            and getattr(self.processors[0], 'processor_chunk_size', 0) > 0)\n+\n     def process_changes(self, since, forever):\n         \"\"\"\n-        Process changes from the changes stream.\n+        Handle changes stream from the changes stream and pass it to processors\n         \"\"\"\n         context = PillowRuntimeContext(changes_seen=0)\n         try:\n+            changes_chunk = []\n             for change in self.get_change_feed().iter_changes(since=since or None, forever=forever):\n                 if change:\n                     context.changes_seen += 1\n-                    self.process_with_error_handling(change, context)\n+                    if self._should_process_in_chunks:\n+                        changes_chunk.append(change)\n+                        if len(changes_chunk) == self.processors[0].processor_chunk_size:\n+                            self.process_chunk_with_error_handling(changes_chunk, context)\n+                            changes_chunk = []\n+                    else:\n+                        self.process_with_error_handling(change, context)\n                 else:\n                     self._update_checkpoint(None, None)\n+            self.process_chunk_with_error_handling(changes_chunk, context)\n         except PillowtopCheckpointReset:\n+            # finish processing any ramining chunk\n+            self.process_chunk_with_error_handling(changes_chunk, context)\n             self.process_changes(since=self.get_last_checkpoint_sequence(), forever=forever)\n \n-    def process_with_error_handling(self, change, context):\n+    def process_chunk_with_error_handling(self, changes_chunk, context):\n+        \"\"\"\n+        Passes given changes_chunk to the processor for chunked processing\n+            If there is an exception in chunked processing, falls back\n+            to passing changes one by one to the processor\n+        \"\"\"\n+        if not changes_chunk:\n+            return\n+        failed_changes = set()\n+        try:\n+            # chunked processing is supported if there is only one processor\n+            failed_changes = self.processors[0].process_changes_chunk(self, changes_chunk)\n+        except Exception as ex:\n+            notify_exception(\n+                None,\n+                \"{pillow_name} Error in processing changes chunk {change_ids}: {ex}\".format(\n+                    pillow_name=self.get_name(),\n+                    change_ids=[c.id for c in changes_chunk],\n+                    ex=ex\n+                ))\n+            # fall back to processing one by one\n+            for change in changes_chunk:\n+                self.process_with_error_handling(change, context, chunked_fallback=True)\n+        else:\n+            succeeded_changes = set(changes_chunk) - set(failed_changes)\n+            for change in succeeded_changes:\n+                self._update_checkpoint(change, context)\n+            # fall back to processing one by one for failed changes\n+            for change in failed_changes:\n+                self.process_with_error_handling(change, context, chunked_fallback=True)\n+        self._record_datadog_metrics(changes_chunk, failed_changes)\n+\n+    def _record_datadog_metrics(self, changes_chunk, failed_changes):\n+        tags = [\"pillow_name:{}\".format(self.get_name())]\n+        datadog_counter('commcare.change_feed.chunked.changes', len(changes_chunk), tags=tags)\n+        datadog_counter('commcare.change_feed.chunked.changes.exception', len(changes_chunk), tags=tags)\n+        datadog_counter('commcare.change_feed.chunked.changes.suceess', len(set(changes_chunk) - set(failed_changes)), tags=tags)","path":"corehq/ex-submodules/pillowtop/pillow/interface.py","position":82,"original_position":82,"commit_id":"25845e930cc894f6107eeba656dd42972edcfe13","original_commit_id":"25845e930cc894f6107eeba656dd42972edcfe13","user":{"login":"stickler-ci","id":16011037,"node_id":"MDQ6VXNlcjE2MDExMDM3","avatar_url":"https://avatars3.githubusercontent.com/u/16011037?v=4","gravatar_id":"","url":"https://api.github.com/users/stickler-ci","html_url":"https://github.com/stickler-ci","followers_url":"https://api.github.com/users/stickler-ci/followers","following_url":"https://api.github.com/users/stickler-ci/following{/other_user}","gists_url":"https://api.github.com/users/stickler-ci/gists{/gist_id}","starred_url":"https://api.github.com/users/stickler-ci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stickler-ci/subscriptions","organizations_url":"https://api.github.com/users/stickler-ci/orgs","repos_url":"https://api.github.com/users/stickler-ci/repos","events_url":"https://api.github.com/users/stickler-ci/events{/privacy}","received_events_url":"https://api.github.com/users/stickler-ci/received_events","type":"User","site_admin":false},"body":"E501 line too long (129 > 115 characters)","created_at":"2018-06-18T15:17:38Z","updated_at":"2018-06-18T15:17:39Z","html_url":"https://github.com/dimagi/commcare-hq/pull/20834#discussion_r196117685","pull_request_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/20834","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments/196117685"},"html":{"href":"https://github.com/dimagi/commcare-hq/pull/20834#discussion_r196117685"},"pull_request":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/20834"}}},"pull_request":{"url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/20834","id":193576665,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkzNTc2NjY1","html_url":"https://github.com/dimagi/commcare-hq/pull/20834","diff_url":"https://github.com/dimagi/commcare-hq/pull/20834.diff","patch_url":"https://github.com/dimagi/commcare-hq/pull/20834.patch","issue_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/20834","number":20834,"state":"open","locked":false,"title":"batch ucrpillow","user":{"login":"sravfeyn","id":829142,"node_id":"MDQ6VXNlcjgyOTE0Mg==","avatar_url":"https://avatars0.githubusercontent.com/u/829142?v=4","gravatar_id":"","url":"https://api.github.com/users/sravfeyn","html_url":"https://github.com/sravfeyn","followers_url":"https://api.github.com/users/sravfeyn/followers","following_url":"https://api.github.com/users/sravfeyn/following{/other_user}","gists_url":"https://api.github.com/users/sravfeyn/gists{/gist_id}","starred_url":"https://api.github.com/users/sravfeyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sravfeyn/subscriptions","organizations_url":"https://api.github.com/users/sravfeyn/orgs","repos_url":"https://api.github.com/users/sravfeyn/repos","events_url":"https://api.github.com/users/sravfeyn/events{/privacy}","received_events_url":"https://api.github.com/users/sravfeyn/received_events","type":"User","site_admin":false},"body":"This PR\r\n1. Introduces a `BulkPillowProcessor` class\r\n2. Extends the current `PillowBase` to pass changes in chunks if the attached processor is `BulkPillowProcessor` (and couple of other conditions, see code for details)\r\n3. Implements `process_change_chunk` for the UCR `ConfigurableReportKafkaPillow`\r\n ","created_at":"2018-06-08T10:45:27Z","updated_at":"2018-06-18T15:17:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bd58964a40128697e55a17a8b068cf41e9ac55be","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":79032211,"node_id":"MDU6TGFiZWw3OTAzMjIxMQ==","url":"https://api.github.com/repos/dimagi/commcare-hq/labels/Open%20for%20review:%20hold%20off%20on%20merge","name":"Open for review: hold off on merge","color":"5319e7","default":false},{"id":724787015,"node_id":"MDU6TGFiZWw3MjQ3ODcwMTU=","url":"https://api.github.com/repos/dimagi/commcare-hq/labels/product/invisible","name":"product/invisible","color":"cfd2d6","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/20834/commits","review_comments_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/20834/comments","review_comment_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/20834/comments","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/25845e930cc894f6107eeba656dd42972edcfe13","head":{"label":"dimagi:sr-batch-ucrpillow","ref":"sr-batch-ucrpillow","sha":"25845e930cc894f6107eeba656dd42972edcfe13","user":{"login":"dimagi","id":94514,"node_id":"MDEyOk9yZ2FuaXphdGlvbjk0NTE0","avatar_url":"https://avatars1.githubusercontent.com/u/94514?v=4","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":247278,"node_id":"MDEwOlJlcG9zaXRvcnkyNDcyNzg=","name":"commcare-hq","full_name":"dimagi/commcare-hq","owner":{"login":"dimagi","id":94514,"node_id":"MDEyOk9yZ2FuaXphdGlvbjk0NTE0","avatar_url":"https://avatars1.githubusercontent.com/u/94514?v=4","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/commcare-hq","description":"A server-side tool to help manage community health workers, written in Django","fork":false,"url":"https://api.github.com/repos/dimagi/commcare-hq","forks_url":"https://api.github.com/repos/dimagi/commcare-hq/forks","keys_url":"https://api.github.com/repos/dimagi/commcare-hq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/commcare-hq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/commcare-hq/teams","hooks_url":"https://api.github.com/repos/dimagi/commcare-hq/hooks","issue_events_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/commcare-hq/events","assignees_url":"https://api.github.com/repos/dimagi/commcare-hq/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/commcare-hq/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/commcare-hq/tags","blobs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/commcare-hq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/commcare-hq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/commcare-hq/languages","stargazers_url":"https://api.github.com/repos/dimagi/commcare-hq/stargazers","contributors_url":"https://api.github.com/repos/dimagi/commcare-hq/contributors","subscribers_url":"https://api.github.com/repos/dimagi/commcare-hq/subscribers","subscription_url":"https://api.github.com/repos/dimagi/commcare-hq/subscription","commits_url":"https://api.github.com/repos/dimagi/commcare-hq/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/commcare-hq/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/commcare-hq/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/commcare-hq/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/commcare-hq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/commcare-hq/merges","archive_url":"https://api.github.com/repos/dimagi/commcare-hq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/commcare-hq/downloads","issues_url":"https://api.github.com/repos/dimagi/commcare-hq/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/commcare-hq/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/commcare-hq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/commcare-hq/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/commcare-hq/releases{/id}","deployments_url":"https://api.github.com/repos/dimagi/commcare-hq/deployments","created_at":"2009-07-09T17:00:07Z","updated_at":"2018-06-18T14:50:27Z","pushed_at":"2018-06-18T15:16:13Z","git_url":"git://github.com/dimagi/commcare-hq.git","ssh_url":"git@github.com:dimagi/commcare-hq.git","clone_url":"https://github.com/dimagi/commcare-hq.git","svn_url":"https://github.com/dimagi/commcare-hq","homepage":"https://www.commcarehq.org","size":443006,"stargazers_count":93,"watchers_count":93,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":106,"mirror_url":null,"archived":false,"open_issues_count":80,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":106,"open_issues":80,"watchers":93,"default_branch":"master"}},"base":{"label":"dimagi:master","ref":"master","sha":"86447bcb6086b4f64f0a252b9b920e3c15a7d98e","user":{"login":"dimagi","id":94514,"node_id":"MDEyOk9yZ2FuaXphdGlvbjk0NTE0","avatar_url":"https://avatars1.githubusercontent.com/u/94514?v=4","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":247278,"node_id":"MDEwOlJlcG9zaXRvcnkyNDcyNzg=","name":"commcare-hq","full_name":"dimagi/commcare-hq","owner":{"login":"dimagi","id":94514,"node_id":"MDEyOk9yZ2FuaXphdGlvbjk0NTE0","avatar_url":"https://avatars1.githubusercontent.com/u/94514?v=4","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/commcare-hq","description":"A server-side tool to help manage community health workers, written in Django","fork":false,"url":"https://api.github.com/repos/dimagi/commcare-hq","forks_url":"https://api.github.com/repos/dimagi/commcare-hq/forks","keys_url":"https://api.github.com/repos/dimagi/commcare-hq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/commcare-hq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/commcare-hq/teams","hooks_url":"https://api.github.com/repos/dimagi/commcare-hq/hooks","issue_events_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/commcare-hq/events","assignees_url":"https://api.github.com/repos/dimagi/commcare-hq/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/commcare-hq/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/commcare-hq/tags","blobs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/commcare-hq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/commcare-hq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/commcare-hq/languages","stargazers_url":"https://api.github.com/repos/dimagi/commcare-hq/stargazers","contributors_url":"https://api.github.com/repos/dimagi/commcare-hq/contributors","subscribers_url":"https://api.github.com/repos/dimagi/commcare-hq/subscribers","subscription_url":"https://api.github.com/repos/dimagi/commcare-hq/subscription","commits_url":"https://api.github.com/repos/dimagi/commcare-hq/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/commcare-hq/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/commcare-hq/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/commcare-hq/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/commcare-hq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/commcare-hq/merges","archive_url":"https://api.github.com/repos/dimagi/commcare-hq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/commcare-hq/downloads","issues_url":"https://api.github.com/repos/dimagi/commcare-hq/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/commcare-hq/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/commcare-hq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/commcare-hq/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/commcare-hq/releases{/id}","deployments_url":"https://api.github.com/repos/dimagi/commcare-hq/deployments","created_at":"2009-07-09T17:00:07Z","updated_at":"2018-06-18T14:50:27Z","pushed_at":"2018-06-18T15:16:13Z","git_url":"git://github.com/dimagi/commcare-hq.git","ssh_url":"git@github.com:dimagi/commcare-hq.git","clone_url":"https://github.com/dimagi/commcare-hq.git","svn_url":"https://github.com/dimagi/commcare-hq","homepage":"https://www.commcarehq.org","size":443006,"stargazers_count":93,"watchers_count":93,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":106,"mirror_url":null,"archived":false,"open_issues_count":80,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":106,"open_issues":80,"watchers":93,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/20834"},"html":{"href":"https://github.com/dimagi/commcare-hq/pull/20834"},"issue":{"href":"https://api.github.com/repos/dimagi/commcare-hq/issues/20834"},"comments":{"href":"https://api.github.com/repos/dimagi/commcare-hq/issues/20834/comments"},"review_comments":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/20834/comments"},"review_comment":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/20834/commits"},"statuses":{"href":"https://api.github.com/repos/dimagi/commcare-hq/statuses/25845e930cc894f6107eeba656dd42972edcfe13"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"stickler-ci"}}