{"action":"created","comment":{"url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments/141574942","pull_request_review_id":65805945,"id":141574942,"diff_hunk":"@@ -0,0 +1,85 @@\n+import csv\n+import datetime\n+import re\n+import time\n+\n+from django.core.management.base import BaseCommand\n+\n+from corehq.motech.repeaters.const import RECORD_CANCELLED_STATE\n+from corehq.motech.repeaters.dbaccessors import iter_repeat_records_by_domain\n+\n+\n+class Command(BaseCommand):\n+    help = \"\"\"\n+    Send cancelled repeat records. You may optionally specify a regex to\n+    filter records using --include or --exclude, an a sleep time with --sleep\n+    \"\"\"\n+\n+    def add_arguments(self, parser):\n+        parser.add_argument('domain')\n+        parser.add_argument('repeater_id')\n+        parser.add_argument(\n+            '--include',\n+            dest='include_regex',\n+            help=(\"Regex that will be applied to a record's 'failure_reason' to \"\n+                  \"determine whether to include it.\"),\n+        )\n+        parser.add_argument(\n+            '--exclude',\n+            dest='exclude_regex',\n+            help=(\"Regex that will be applied to a record's 'failure_reason' to \"\n+                  \"determine whether to exclude it.\"),\n+        )\n+        parser.add_argument(\n+            '--sleep',\n+            dest='sleep_time',\n+            help=\"Time in seconds to sleep between each request.\",\n+        )\n+\n+    def handle(self, domain, repeater_id, *args, **options):\n+        sleep_time = options.get('sleep_time')\n+        include_regex = options.get('include_regex')\n+        exclude_regex = options.get('exclude_regex')\n+        if include_regex and exclude_regex:\n+            print \"You may not specify both include and exclude\"\n+\n+        def meets_filter(record):\n+            if include_regex:\n+                if not record.failure_reason:\n+                    return False\n+                return bool(re.search(include_regex, record.failure_reason))\n+            elif exclude_regex:\n+                if not record.failure_reason:\n+                    return True\n+                return not bool(re.search(exclude_regex, record.failure_reason))\n+            return True  # No filter applied\n+\n+        records = filter(\n+            meets_filter,\n+            iter_repeat_records_by_domain(domain, repeater_id=repeater_id, state=RECORD_CANCELLED_STATE)\n+        )\n+\n+        total_records = len(records)\n+        print \"Found {} matching records.  Requeue them?\".format(total_records)\n+        if not raw_input(\"(y/n)\") == 'y':\n+            print \"Aborting\"\n+            return\n+\n+        log = [('record_id', 'payload_id', 'state', 'failure_reason')]\n+        for i, record in enumerate(records):\n+            try:\n+                record.fire(force_send=True)","path":"corehq/motech/repeaters/management/commands/send_cancelled_records.py","position":71,"original_position":71,"commit_id":"a6c8176e3f4602e846888293093fc64b7b20233b","original_commit_id":"a6c8176e3f4602e846888293093fc64b7b20233b","user":{"login":"mkangia","id":3864163,"avatar_url":"https://avatars3.githubusercontent.com/u/3864163?v=4","gravatar_id":"","url":"https://api.github.com/users/mkangia","html_url":"https://github.com/mkangia","followers_url":"https://api.github.com/users/mkangia/followers","following_url":"https://api.github.com/users/mkangia/following{/other_user}","gists_url":"https://api.github.com/users/mkangia/gists{/gist_id}","starred_url":"https://api.github.com/users/mkangia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkangia/subscriptions","organizations_url":"https://api.github.com/users/mkangia/orgs","repos_url":"https://api.github.com/users/mkangia/repos","events_url":"https://api.github.com/users/mkangia/events{/privacy}","received_events_url":"https://api.github.com/users/mkangia/received_events","type":"User","site_admin":false},"body":"Not sure if you have tested this but this failed for me when retriggering cancelled records due to next check on the record being blank. I am not 100% sure but i think it fails [here](https://github.com/dimagi/commcare-hq/blob/master/corehq/motech/repeaters/models.py#L574)\r\nyou might have to add [this](https://github.com/dimagi/commcare-hq/blob/master/custom/enikshay/management/commands/retrigger_private_nikshay_records.py#L147)","created_at":"2017-09-28T09:54:16Z","updated_at":"2017-09-28T10:01:26Z","html_url":"https://github.com/dimagi/commcare-hq/pull/17995#discussion_r141574942","pull_request_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/17995","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments/141574942"},"html":{"href":"https://github.com/dimagi/commcare-hq/pull/17995#discussion_r141574942"},"pull_request":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/17995"}}},"pull_request":{"url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/17995","id":143519517,"html_url":"https://github.com/dimagi/commcare-hq/pull/17995","diff_url":"https://github.com/dimagi/commcare-hq/pull/17995.diff","patch_url":"https://github.com/dimagi/commcare-hq/pull/17995.patch","issue_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/17995","number":17995,"state":"open","locked":false,"title":"Add commands to deduplicate and send repeat records","user":{"login":"esoergel","id":2367539,"avatar_url":"https://avatars2.githubusercontent.com/u/2367539?v=4","gravatar_id":"","url":"https://api.github.com/users/esoergel","html_url":"https://github.com/esoergel","followers_url":"https://api.github.com/users/esoergel/followers","following_url":"https://api.github.com/users/esoergel/following{/other_user}","gists_url":"https://api.github.com/users/esoergel/gists{/gist_id}","starred_url":"https://api.github.com/users/esoergel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/esoergel/subscriptions","organizations_url":"https://api.github.com/users/esoergel/orgs","repos_url":"https://api.github.com/users/esoergel/repos","events_url":"https://api.github.com/users/esoergel/events{/privacy}","received_events_url":"https://api.github.com/users/esoergel/received_events","type":"User","site_admin":false},"body":"@proteusvacuum @dannyroberts\nThoughts on the general approach here?  I discussed the deduplication with Danny yesterday and we could also use an approach which doesn't delete any records of attempts, such as either save to another bucket that's not \"CANCELLED\", or to add those attempts to the repeat record that we'll be keeping.  I'm not sure either gives us much actual value, so I decided to keep it simple unless someone makes a case for keeping them.\n\nbuddy: @mkangia","created_at":"2017-09-27T22:57:05Z","updated_at":"2017-09-28T10:01:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"abcf7046f91726a1b0d33522d380ece69ac8ac27","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/17995/commits","review_comments_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/17995/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/17995/comments","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/a6c8176e3f4602e846888293093fc64b7b20233b","head":{"label":"dimagi:es/delete-duplicate-records","ref":"es/delete-duplicate-records","sha":"a6c8176e3f4602e846888293093fc64b7b20233b","user":{"login":"dimagi","id":94514,"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,"name":"commcare-hq","full_name":"dimagi/commcare-hq","owner":{"login":"dimagi","id":94514,"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":"2017-09-08T11:11:20Z","pushed_at":"2017-09-28T09:25:59Z","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":423269,"stargazers_count":79,"watchers_count":79,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":94,"mirror_url":null,"open_issues_count":54,"forks":94,"open_issues":54,"watchers":79,"default_branch":"master"}},"base":{"label":"dimagi:master","ref":"master","sha":"d10f84ce3bd3005b3daf93e2aa9859197462f5b5","user":{"login":"dimagi","id":94514,"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,"name":"commcare-hq","full_name":"dimagi/commcare-hq","owner":{"login":"dimagi","id":94514,"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":"2017-09-08T11:11:20Z","pushed_at":"2017-09-28T09:25:59Z","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":423269,"stargazers_count":79,"watchers_count":79,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":94,"mirror_url":null,"open_issues_count":54,"forks":94,"open_issues":54,"watchers":79,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/17995"},"html":{"href":"https://github.com/dimagi/commcare-hq/pull/17995"},"issue":{"href":"https://api.github.com/repos/dimagi/commcare-hq/issues/17995"},"comments":{"href":"https://api.github.com/repos/dimagi/commcare-hq/issues/17995/comments"},"review_comments":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/17995/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/17995/commits"},"statuses":{"href":"https://api.github.com/repos/dimagi/commcare-hq/statuses/a6c8176e3f4602e846888293093fc64b7b20233b"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"mkangia"}}