{"action":"created","comment":{"url":"https://api.github.com/repos/motech-implementations/mim/pulls/comments/42097739","id":42097739,"diff_hunk":"@@ -156,31 +156,62 @@ private boolean isMsisdnInvalid(CallSummaryRecord record) {\n     }\n \n \n+    private boolean isFirstMessageOfWeek(String weekId) {\n+        return weekId.endsWith(\"1\");\n+    }\n+\n+\n     private void rescheduleCall(Subscription subscription, CallSummaryRecord record, CallRetry callRetry) {\n \n         Long msisdn = subscription.getSubscriber().getCallingNumber();\n \n-        if (callRetry == null) {\n-\n-            // This message was never retried before, so this is a first retry\n-            LOGGER.debug(String.format(\"Creating retry for subscription: %s\", subscription.getSubscriptionId()));\n-            DayOfTheWeek nextDay = DayOfTheWeek.fromInt(subscription.getStartDate().dayOfWeek().get()).nextDay();\n-            CallRetry newCallRetry = new CallRetry(\n-                    subscription.getSubscriptionId(),\n-                    msisdn,\n-                    nextDay,\n-                    CallStage.RETRY_1,\n-                    record.getContentFileName(),\n-                    record.getWeekId(),\n-                    getLanguageCode(subscription),\n-                    getCircleName(subscription),\n-                    subscription.getOrigin()\n-            );\n-            callRetryDataService.create(newCallRetry);\n+        if (callRetry == null || !callRetry.getWeekId().equals(record.getWeekId())) {\n+\n+            // This message was never retried for this week before, so this is a first retry\n+            LOGGER.debug(String.format(\"Creating retry for subscription %s and weekId %s\",\n+                    subscription.getSubscriptionId(), record.getWeekId()));\n+\n+            // Looking at the weekId, we can figure out if this was the first or second message for that week\n+            // and calculate which day of the week we should reschedule the call for\n+            DayOfTheWeek nextDay;\n+            if (isFirstMessageOfWeek(record.getWeekId())) {\n+                nextDay = subscription.getFirstMessageDayOfWeek().nextDay();\n+            } else {\n+                nextDay = subscription.getSecondMessageDayOfWeek().nextDay();\n+            }\n+\n+            if (callRetry == null) {\n+                // no retry was ever tried\n+\n+                CallRetry newCallRetry = new CallRetry(\n+                        subscription.getSubscriptionId(),\n+                        msisdn,\n+                        nextDay,\n+                        CallStage.RETRY_1,\n+                        record.getContentFileName(),\n+                        record.getWeekId(),\n+                        getLanguageCode(subscription),\n+                        getCircleName(subscription),\n+                        subscription.getOrigin()\n+                );\n+                callRetryDataService.create(newCallRetry);\n+            } else {","path":"kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/CsrServiceImpl.java","position":60,"original_position":60,"commit_id":"6bbb8d1e866bb78748ed6f4cd1ff1bf981a59fe8","original_commit_id":"6bbb8d1e866bb78748ed6f4cd1ff1bf981a59fe8","user":{"login":"koshalt","id":6786794,"avatar_url":"https://avatars.githubusercontent.com/u/6786794?v=3","gravatar_id":"","url":"https://api.github.com/users/koshalt","html_url":"https://github.com/koshalt","followers_url":"https://api.github.com/users/koshalt/followers","following_url":"https://api.github.com/users/koshalt/following{/other_user}","gists_url":"https://api.github.com/users/koshalt/gists{/gist_id}","starred_url":"https://api.github.com/users/koshalt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/koshalt/subscriptions","organizations_url":"https://api.github.com/users/koshalt/orgs","repos_url":"https://api.github.com/users/koshalt/repos","events_url":"https://api.github.com/users/koshalt/events{/privacy}","received_events_url":"https://api.github.com/users/koshalt/received_events","type":"User","site_admin":false},"body":"I'm confused by the else block here. This means that a retry entry already exists. Why would we overwrite it to Retry_1 again?","created_at":"2015-10-15T08:54:10Z","updated_at":"2015-10-15T08:54:10Z","html_url":"https://github.com/motech-implementations/mim/pull/625#discussion_r42097739","pull_request_url":"https://api.github.com/repos/motech-implementations/mim/pulls/625","_links":{"self":{"href":"https://api.github.com/repos/motech-implementations/mim/pulls/comments/42097739"},"html":{"href":"https://github.com/motech-implementations/mim/pull/625#discussion_r42097739"},"pull_request":{"href":"https://api.github.com/repos/motech-implementations/mim/pulls/625"}}},"pull_request":{"url":"https://api.github.com/repos/motech-implementations/mim/pulls/625","id":47686526,"html_url":"https://github.com/motech-implementations/mim/pull/625","diff_url":"https://github.com/motech-implementations/mim/pull/625.diff","patch_url":"https://github.com/motech-implementations/mim/pull/625.patch","issue_url":"https://api.github.com/repos/motech-implementations/mim/issues/625","number":625,"state":"open","locked":false,"title":"Fixed mistaken reschedule of second weekly message","user":{"login":"frankhuster","id":5107550,"avatar_url":"https://avatars.githubusercontent.com/u/5107550?v=3","gravatar_id":"","url":"https://api.github.com/users/frankhuster","html_url":"https://github.com/frankhuster","followers_url":"https://api.github.com/users/frankhuster/followers","following_url":"https://api.github.com/users/frankhuster/following{/other_user}","gists_url":"https://api.github.com/users/frankhuster/gists{/gist_id}","starred_url":"https://api.github.com/users/frankhuster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frankhuster/subscriptions","organizations_url":"https://api.github.com/users/frankhuster/orgs","repos_url":"https://api.github.com/users/frankhuster/repos","events_url":"https://api.github.com/users/frankhuster/events{/privacy}","received_events_url":"https://api.github.com/users/frankhuster/received_events","type":"User","site_admin":false},"body":"Great bug find by Manjot (or  was is Rahul?)","created_at":"2015-10-14T17:01:30Z","updated_at":"2015-10-15T08:54:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a04f6da5e7f8d25be24bb415c67d1e1503308d26","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/motech-implementations/mim/pulls/625/commits","review_comments_url":"https://api.github.com/repos/motech-implementations/mim/pulls/625/comments","review_comment_url":"https://api.github.com/repos/motech-implementations/mim/pulls/comments{/number}","comments_url":"https://api.github.com/repos/motech-implementations/mim/issues/625/comments","statuses_url":"https://api.github.com/repos/motech-implementations/mim/statuses/6bbb8d1e866bb78748ed6f4cd1ff1bf981a59fe8","head":{"label":"motech-implementations:rescheduleTwoMessages","ref":"rescheduleTwoMessages","sha":"6bbb8d1e866bb78748ed6f4cd1ff1bf981a59fe8","user":{"login":"motech-implementations","id":6608253,"avatar_url":"https://avatars.githubusercontent.com/u/6608253?v=3","gravatar_id":"","url":"https://api.github.com/users/motech-implementations","html_url":"https://github.com/motech-implementations","followers_url":"https://api.github.com/users/motech-implementations/followers","following_url":"https://api.github.com/users/motech-implementations/following{/other_user}","gists_url":"https://api.github.com/users/motech-implementations/gists{/gist_id}","starred_url":"https://api.github.com/users/motech-implementations/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/motech-implementations/subscriptions","organizations_url":"https://api.github.com/users/motech-implementations/orgs","repos_url":"https://api.github.com/users/motech-implementations/repos","events_url":"https://api.github.com/users/motech-implementations/events{/privacy}","received_events_url":"https://api.github.com/users/motech-implementations/received_events","type":"Organization","site_admin":false},"repo":{"id":33508795,"name":"mim","full_name":"motech-implementations/mim","owner":{"login":"motech-implementations","id":6608253,"avatar_url":"https://avatars.githubusercontent.com/u/6608253?v=3","gravatar_id":"","url":"https://api.github.com/users/motech-implementations","html_url":"https://github.com/motech-implementations","followers_url":"https://api.github.com/users/motech-implementations/followers","following_url":"https://api.github.com/users/motech-implementations/following{/other_user}","gists_url":"https://api.github.com/users/motech-implementations/gists{/gist_id}","starred_url":"https://api.github.com/users/motech-implementations/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/motech-implementations/subscriptions","organizations_url":"https://api.github.com/users/motech-implementations/orgs","repos_url":"https://api.github.com/users/motech-implementations/repos","events_url":"https://api.github.com/users/motech-implementations/events{/privacy}","received_events_url":"https://api.github.com/users/motech-implementations/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/motech-implementations/mim","description":"mim","fork":false,"url":"https://api.github.com/repos/motech-implementations/mim","forks_url":"https://api.github.com/repos/motech-implementations/mim/forks","keys_url":"https://api.github.com/repos/motech-implementations/mim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/motech-implementations/mim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/motech-implementations/mim/teams","hooks_url":"https://api.github.com/repos/motech-implementations/mim/hooks","issue_events_url":"https://api.github.com/repos/motech-implementations/mim/issues/events{/number}","events_url":"https://api.github.com/repos/motech-implementations/mim/events","assignees_url":"https://api.github.com/repos/motech-implementations/mim/assignees{/user}","branches_url":"https://api.github.com/repos/motech-implementations/mim/branches{/branch}","tags_url":"https://api.github.com/repos/motech-implementations/mim/tags","blobs_url":"https://api.github.com/repos/motech-implementations/mim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/motech-implementations/mim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/motech-implementations/mim/git/refs{/sha}","trees_url":"https://api.github.com/repos/motech-implementations/mim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/motech-implementations/mim/statuses/{sha}","languages_url":"https://api.github.com/repos/motech-implementations/mim/languages","stargazers_url":"https://api.github.com/repos/motech-implementations/mim/stargazers","contributors_url":"https://api.github.com/repos/motech-implementations/mim/contributors","subscribers_url":"https://api.github.com/repos/motech-implementations/mim/subscribers","subscription_url":"https://api.github.com/repos/motech-implementations/mim/subscription","commits_url":"https://api.github.com/repos/motech-implementations/mim/commits{/sha}","git_commits_url":"https://api.github.com/repos/motech-implementations/mim/git/commits{/sha}","comments_url":"https://api.github.com/repos/motech-implementations/mim/comments{/number}","issue_comment_url":"https://api.github.com/repos/motech-implementations/mim/issues/comments{/number}","contents_url":"https://api.github.com/repos/motech-implementations/mim/contents/{+path}","compare_url":"https://api.github.com/repos/motech-implementations/mim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/motech-implementations/mim/merges","archive_url":"https://api.github.com/repos/motech-implementations/mim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/motech-implementations/mim/downloads","issues_url":"https://api.github.com/repos/motech-implementations/mim/issues{/number}","pulls_url":"https://api.github.com/repos/motech-implementations/mim/pulls{/number}","milestones_url":"https://api.github.com/repos/motech-implementations/mim/milestones{/number}","notifications_url":"https://api.github.com/repos/motech-implementations/mim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/motech-implementations/mim/labels{/name}","releases_url":"https://api.github.com/repos/motech-implementations/mim/releases{/id}","created_at":"2015-04-06T22:18:18Z","updated_at":"2015-08-28T05:34:53Z","pushed_at":"2015-10-15T07:01:14Z","git_url":"git://github.com/motech-implementations/mim.git","ssh_url":"git@github.com:motech-implementations/mim.git","clone_url":"https://github.com/motech-implementations/mim.git","svn_url":"https://github.com/motech-implementations/mim","homepage":null,"size":56584,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":21,"forks":7,"open_issues":21,"watchers":1,"default_branch":"master"}},"base":{"label":"motech-implementations:master","ref":"master","sha":"ff2dd4b6b18b4185270dd0200a6227cb8910fe0e","user":{"login":"motech-implementations","id":6608253,"avatar_url":"https://avatars.githubusercontent.com/u/6608253?v=3","gravatar_id":"","url":"https://api.github.com/users/motech-implementations","html_url":"https://github.com/motech-implementations","followers_url":"https://api.github.com/users/motech-implementations/followers","following_url":"https://api.github.com/users/motech-implementations/following{/other_user}","gists_url":"https://api.github.com/users/motech-implementations/gists{/gist_id}","starred_url":"https://api.github.com/users/motech-implementations/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/motech-implementations/subscriptions","organizations_url":"https://api.github.com/users/motech-implementations/orgs","repos_url":"https://api.github.com/users/motech-implementations/repos","events_url":"https://api.github.com/users/motech-implementations/events{/privacy}","received_events_url":"https://api.github.com/users/motech-implementations/received_events","type":"Organization","site_admin":false},"repo":{"id":33508795,"name":"mim","full_name":"motech-implementations/mim","owner":{"login":"motech-implementations","id":6608253,"avatar_url":"https://avatars.githubusercontent.com/u/6608253?v=3","gravatar_id":"","url":"https://api.github.com/users/motech-implementations","html_url":"https://github.com/motech-implementations","followers_url":"https://api.github.com/users/motech-implementations/followers","following_url":"https://api.github.com/users/motech-implementations/following{/other_user}","gists_url":"https://api.github.com/users/motech-implementations/gists{/gist_id}","starred_url":"https://api.github.com/users/motech-implementations/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/motech-implementations/subscriptions","organizations_url":"https://api.github.com/users/motech-implementations/orgs","repos_url":"https://api.github.com/users/motech-implementations/repos","events_url":"https://api.github.com/users/motech-implementations/events{/privacy}","received_events_url":"https://api.github.com/users/motech-implementations/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/motech-implementations/mim","description":"mim","fork":false,"url":"https://api.github.com/repos/motech-implementations/mim","forks_url":"https://api.github.com/repos/motech-implementations/mim/forks","keys_url":"https://api.github.com/repos/motech-implementations/mim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/motech-implementations/mim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/motech-implementations/mim/teams","hooks_url":"https://api.github.com/repos/motech-implementations/mim/hooks","issue_events_url":"https://api.github.com/repos/motech-implementations/mim/issues/events{/number}","events_url":"https://api.github.com/repos/motech-implementations/mim/events","assignees_url":"https://api.github.com/repos/motech-implementations/mim/assignees{/user}","branches_url":"https://api.github.com/repos/motech-implementations/mim/branches{/branch}","tags_url":"https://api.github.com/repos/motech-implementations/mim/tags","blobs_url":"https://api.github.com/repos/motech-implementations/mim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/motech-implementations/mim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/motech-implementations/mim/git/refs{/sha}","trees_url":"https://api.github.com/repos/motech-implementations/mim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/motech-implementations/mim/statuses/{sha}","languages_url":"https://api.github.com/repos/motech-implementations/mim/languages","stargazers_url":"https://api.github.com/repos/motech-implementations/mim/stargazers","contributors_url":"https://api.github.com/repos/motech-implementations/mim/contributors","subscribers_url":"https://api.github.com/repos/motech-implementations/mim/subscribers","subscription_url":"https://api.github.com/repos/motech-implementations/mim/subscription","commits_url":"https://api.github.com/repos/motech-implementations/mim/commits{/sha}","git_commits_url":"https://api.github.com/repos/motech-implementations/mim/git/commits{/sha}","comments_url":"https://api.github.com/repos/motech-implementations/mim/comments{/number}","issue_comment_url":"https://api.github.com/repos/motech-implementations/mim/issues/comments{/number}","contents_url":"https://api.github.com/repos/motech-implementations/mim/contents/{+path}","compare_url":"https://api.github.com/repos/motech-implementations/mim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/motech-implementations/mim/merges","archive_url":"https://api.github.com/repos/motech-implementations/mim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/motech-implementations/mim/downloads","issues_url":"https://api.github.com/repos/motech-implementations/mim/issues{/number}","pulls_url":"https://api.github.com/repos/motech-implementations/mim/pulls{/number}","milestones_url":"https://api.github.com/repos/motech-implementations/mim/milestones{/number}","notifications_url":"https://api.github.com/repos/motech-implementations/mim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/motech-implementations/mim/labels{/name}","releases_url":"https://api.github.com/repos/motech-implementations/mim/releases{/id}","created_at":"2015-04-06T22:18:18Z","updated_at":"2015-08-28T05:34:53Z","pushed_at":"2015-10-15T07:01:14Z","git_url":"git://github.com/motech-implementations/mim.git","ssh_url":"git@github.com:motech-implementations/mim.git","clone_url":"https://github.com/motech-implementations/mim.git","svn_url":"https://github.com/motech-implementations/mim","homepage":null,"size":56584,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":21,"forks":7,"open_issues":21,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/motech-implementations/mim/pulls/625"},"html":{"href":"https://github.com/motech-implementations/mim/pull/625"},"issue":{"href":"https://api.github.com/repos/motech-implementations/mim/issues/625"},"comments":{"href":"https://api.github.com/repos/motech-implementations/mim/issues/625/comments"},"review_comments":{"href":"https://api.github.com/repos/motech-implementations/mim/pulls/625/comments"},"review_comment":{"href":"https://api.github.com/repos/motech-implementations/mim/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/motech-implementations/mim/pulls/625/commits"},"statuses":{"href":"https://api.github.com/repos/motech-implementations/mim/statuses/6bbb8d1e866bb78748ed6f4cd1ff1bf981a59fe8"}}}}