{"action":"created","comment":{"url":"https://api.github.com/repos/Azure/pcs-config-java/pulls/comments/185886429","pull_request_review_id":117365991,"id":185886429,"diff_hunk":"@@ -152,18 +152,45 @@ public CompletionStage rebuildCacheAsync(boolean force) throws Exception {\n     }\n \n     private boolean needBuild(boolean force, ValueApiModel twin) {\n-        boolean needBuild = false;\n-        // validate timestamp\n-        if (force || twin == null) {\n-            needBuild = true;\n-        } else {\n-            boolean rebuilding = Json.fromJson(Json.parse(twin.getData()), CacheValue.class).isRebuilding();\n-            DateTimeFormatter formatter = DateTimeFormat.forPattern(\"yyyy-MM-dd'T'HH:mm:ssZZ\");\n-            DateTime timestamp = formatter.parseDateTime(twin.getMetadata().get(\"$modified\"));\n-            needBuild = needBuild || !rebuilding && timestamp.plusSeconds(this.cacheTTL).isBeforeNow();\n-            needBuild = needBuild || rebuilding && timestamp.plusSeconds(this.rebuildTimeout).isBeforeNow();\n+        if (force) {\n+            this.log.info(\"Cache will be rebuilt due to the force flag\");\n+            return true;\n+        }\n+\n+        if (twin == null) {\n+            this.log.info(\"Cache will be rebuilt since no cache was found\");\n+            return true;\n+        }\n+\n+        CacheValue cacheValue = Json.fromJson(Json.parse(twin.getData()), CacheValue.class);\n+        DateTimeFormatter formatter = DateTimeFormat.forPattern(\"yyyy-MM-dd'T'HH:mm:ssZZ\");\n+        DateTime timestamp = formatter.parseDateTime(twin.getMetadata().get(\"$modified\"));\n+        if (cacheValue.isRebuilding()) {\n+            if (timestamp.plusSeconds(this.rebuildTimeout).isBeforeNow()) {\n+                this.log.info(\"Cache will be rebuilt since last rebuilding was timeout\");\n+                return true;\n+            } else {\n+                this.log.info(\"Cache rebuilding skipped since it was rebuilding by other instance\");\n+                return false;\n+            }\n+        }\n+        else\n+        {\n+            if (cacheValue.isNullOrEmpty()) {\n+                this.log.info(\"Cache will be rebuilt since it is empty\");\n+                return true;\n+            }\n+\n+            if (timestamp.plusSeconds(this.cacheTTL).isBeforeNow()) {\n+                this.log.info(\"Cache will be rebuilt since it was expired\");\n+                return true;\n+            }\n+            else\n+            {\n+                this.log.info(\"Cache rebuilding skipped since it was not expired\");","path":"app/com/microsoft/azure/iotsolutions/uiconfig/services/Cache.java","position":49,"original_position":49,"commit_id":"0005d733278493dbf8f19c89ae7a442ac8002401","original_commit_id":"0005d733278493dbf8f19c89ae7a442ac8002401","user":{"login":"avanikp","id":32693971,"avatar_url":"https://avatars1.githubusercontent.com/u/32693971?v=4","gravatar_id":"","url":"https://api.github.com/users/avanikp","html_url":"https://github.com/avanikp","followers_url":"https://api.github.com/users/avanikp/followers","following_url":"https://api.github.com/users/avanikp/following{/other_user}","gists_url":"https://api.github.com/users/avanikp/gists{/gist_id}","starred_url":"https://api.github.com/users/avanikp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/avanikp/subscriptions","organizations_url":"https://api.github.com/users/avanikp/orgs","repos_url":"https://api.github.com/users/avanikp/repos","events_url":"https://api.github.com/users/avanikp/events{/privacy}","received_events_url":"https://api.github.com/users/avanikp/received_events","type":"User","site_admin":false},"body":"nit: Cache rebuilding skipped since it has not expired","created_at":"2018-05-03T17:54:27Z","updated_at":"2018-05-03T17:59:50Z","html_url":"https://github.com/Azure/pcs-config-java/pull/73#discussion_r185886429","pull_request_url":"https://api.github.com/repos/Azure/pcs-config-java/pulls/73","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/Azure/pcs-config-java/pulls/comments/185886429"},"html":{"href":"https://github.com/Azure/pcs-config-java/pull/73#discussion_r185886429"},"pull_request":{"href":"https://api.github.com/repos/Azure/pcs-config-java/pulls/73"}}},"pull_request":{"url":"https://api.github.com/repos/Azure/pcs-config-java/pulls/73","id":185603995,"html_url":"https://github.com/Azure/pcs-config-java/pull/73","diff_url":"https://github.com/Azure/pcs-config-java/pull/73.diff","patch_url":"https://github.com/Azure/pcs-config-java/pull/73.patch","issue_url":"https://api.github.com/repos/Azure/pcs-config-java/issues/73","number":73,"state":"open","locked":false,"title":"Fix bug of caching empty twin properties","user":{"login":"zhang-hua","id":2011059,"avatar_url":"https://avatars1.githubusercontent.com/u/2011059?v=4","gravatar_id":"","url":"https://api.github.com/users/zhang-hua","html_url":"https://github.com/zhang-hua","followers_url":"https://api.github.com/users/zhang-hua/followers","following_url":"https://api.github.com/users/zhang-hua/following{/other_user}","gists_url":"https://api.github.com/users/zhang-hua/gists{/gist_id}","starred_url":"https://api.github.com/users/zhang-hua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhang-hua/subscriptions","organizations_url":"https://api.github.com/users/zhang-hua/orgs","repos_url":"https://api.github.com/users/zhang-hua/repos","events_url":"https://api.github.com/users/zhang-hua/events{/privacy}","received_events_url":"https://api.github.com/users/zhang-hua/received_events","type":"User","site_admin":false},"body":"# Type of change? <!-- [x] all the boxes that apply -->\r\n\r\n- [x] Bug fix\r\n- [ ] New feature\r\n- [ ] Enhancement\r\n- [ ] Breaking change (breaks backward compatibility)\r\n\r\n# Description, Context, Motivation <!-- Please help us reviewing your PR -->\r\n\r\n...\r\n\r\n**Checklist:**\r\n\r\n- [x] All tests passed\r\n- [x] The code follows the code style and conventions of this project\r\n- [ ] The change requires a change to the documentation\r\n- [ ] I have updated the documentation accordingly\r\n","created_at":"2018-05-03T02:18:44Z","updated_at":"2018-05-03T17:59:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"051898e8af1f7cfb614c407f0aeba9c0a6e26498","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/Azure/pcs-config-java/pulls/73/commits","review_comments_url":"https://api.github.com/repos/Azure/pcs-config-java/pulls/73/comments","review_comment_url":"https://api.github.com/repos/Azure/pcs-config-java/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Azure/pcs-config-java/issues/73/comments","statuses_url":"https://api.github.com/repos/Azure/pcs-config-java/statuses/0005d733278493dbf8f19c89ae7a442ac8002401","head":{"label":"Azure:cache_bug","ref":"cache_bug","sha":"0005d733278493dbf8f19c89ae7a442ac8002401","user":{"login":"Azure","id":6844498,"avatar_url":"https://avatars0.githubusercontent.com/u/6844498?v=4","gravatar_id":"","url":"https://api.github.com/users/Azure","html_url":"https://github.com/Azure","followers_url":"https://api.github.com/users/Azure/followers","following_url":"https://api.github.com/users/Azure/following{/other_user}","gists_url":"https://api.github.com/users/Azure/gists{/gist_id}","starred_url":"https://api.github.com/users/Azure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Azure/subscriptions","organizations_url":"https://api.github.com/users/Azure/orgs","repos_url":"https://api.github.com/users/Azure/repos","events_url":"https://api.github.com/users/Azure/events{/privacy}","received_events_url":"https://api.github.com/users/Azure/received_events","type":"Organization","site_admin":false},"repo":{"id":96269429,"name":"pcs-config-java","full_name":"Azure/pcs-config-java","owner":{"login":"Azure","id":6844498,"avatar_url":"https://avatars0.githubusercontent.com/u/6844498?v=4","gravatar_id":"","url":"https://api.github.com/users/Azure","html_url":"https://github.com/Azure","followers_url":"https://api.github.com/users/Azure/followers","following_url":"https://api.github.com/users/Azure/following{/other_user}","gists_url":"https://api.github.com/users/Azure/gists{/gist_id}","starred_url":"https://api.github.com/users/Azure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Azure/subscriptions","organizations_url":"https://api.github.com/users/Azure/orgs","repos_url":"https://api.github.com/users/Azure/repos","events_url":"https://api.github.com/users/Azure/events{/privacy}","received_events_url":"https://api.github.com/users/Azure/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Azure/pcs-config-java","description":"The configuration microservice for Azure IoT Solutions","fork":false,"url":"https://api.github.com/repos/Azure/pcs-config-java","forks_url":"https://api.github.com/repos/Azure/pcs-config-java/forks","keys_url":"https://api.github.com/repos/Azure/pcs-config-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Azure/pcs-config-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Azure/pcs-config-java/teams","hooks_url":"https://api.github.com/repos/Azure/pcs-config-java/hooks","issue_events_url":"https://api.github.com/repos/Azure/pcs-config-java/issues/events{/number}","events_url":"https://api.github.com/repos/Azure/pcs-config-java/events","assignees_url":"https://api.github.com/repos/Azure/pcs-config-java/assignees{/user}","branches_url":"https://api.github.com/repos/Azure/pcs-config-java/branches{/branch}","tags_url":"https://api.github.com/repos/Azure/pcs-config-java/tags","blobs_url":"https://api.github.com/repos/Azure/pcs-config-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Azure/pcs-config-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Azure/pcs-config-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/Azure/pcs-config-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Azure/pcs-config-java/statuses/{sha}","languages_url":"https://api.github.com/repos/Azure/pcs-config-java/languages","stargazers_url":"https://api.github.com/repos/Azure/pcs-config-java/stargazers","contributors_url":"https://api.github.com/repos/Azure/pcs-config-java/contributors","subscribers_url":"https://api.github.com/repos/Azure/pcs-config-java/subscribers","subscription_url":"https://api.github.com/repos/Azure/pcs-config-java/subscription","commits_url":"https://api.github.com/repos/Azure/pcs-config-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/Azure/pcs-config-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/Azure/pcs-config-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/Azure/pcs-config-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/Azure/pcs-config-java/contents/{+path}","compare_url":"https://api.github.com/repos/Azure/pcs-config-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Azure/pcs-config-java/merges","archive_url":"https://api.github.com/repos/Azure/pcs-config-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Azure/pcs-config-java/downloads","issues_url":"https://api.github.com/repos/Azure/pcs-config-java/issues{/number}","pulls_url":"https://api.github.com/repos/Azure/pcs-config-java/pulls{/number}","milestones_url":"https://api.github.com/repos/Azure/pcs-config-java/milestones{/number}","notifications_url":"https://api.github.com/repos/Azure/pcs-config-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Azure/pcs-config-java/labels{/name}","releases_url":"https://api.github.com/repos/Azure/pcs-config-java/releases{/id}","deployments_url":"https://api.github.com/repos/Azure/pcs-config-java/deployments","created_at":"2017-07-05T02:37:33Z","updated_at":"2018-05-02T23:54:28Z","pushed_at":"2018-05-03T02:18:45Z","git_url":"git://github.com/Azure/pcs-config-java.git","ssh_url":"git@github.com:Azure/pcs-config-java.git","clone_url":"https://github.com/Azure/pcs-config-java.git","svn_url":"https://github.com/Azure/pcs-config-java","homepage":"","size":1284,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":7,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":3,"open_issues":7,"watchers":1,"default_branch":"master"}},"base":{"label":"Azure:master","ref":"master","sha":"2cd97298c25e9a0df4df86fb6733d96056fc69eb","user":{"login":"Azure","id":6844498,"avatar_url":"https://avatars0.githubusercontent.com/u/6844498?v=4","gravatar_id":"","url":"https://api.github.com/users/Azure","html_url":"https://github.com/Azure","followers_url":"https://api.github.com/users/Azure/followers","following_url":"https://api.github.com/users/Azure/following{/other_user}","gists_url":"https://api.github.com/users/Azure/gists{/gist_id}","starred_url":"https://api.github.com/users/Azure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Azure/subscriptions","organizations_url":"https://api.github.com/users/Azure/orgs","repos_url":"https://api.github.com/users/Azure/repos","events_url":"https://api.github.com/users/Azure/events{/privacy}","received_events_url":"https://api.github.com/users/Azure/received_events","type":"Organization","site_admin":false},"repo":{"id":96269429,"name":"pcs-config-java","full_name":"Azure/pcs-config-java","owner":{"login":"Azure","id":6844498,"avatar_url":"https://avatars0.githubusercontent.com/u/6844498?v=4","gravatar_id":"","url":"https://api.github.com/users/Azure","html_url":"https://github.com/Azure","followers_url":"https://api.github.com/users/Azure/followers","following_url":"https://api.github.com/users/Azure/following{/other_user}","gists_url":"https://api.github.com/users/Azure/gists{/gist_id}","starred_url":"https://api.github.com/users/Azure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Azure/subscriptions","organizations_url":"https://api.github.com/users/Azure/orgs","repos_url":"https://api.github.com/users/Azure/repos","events_url":"https://api.github.com/users/Azure/events{/privacy}","received_events_url":"https://api.github.com/users/Azure/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Azure/pcs-config-java","description":"The configuration microservice for Azure IoT Solutions","fork":false,"url":"https://api.github.com/repos/Azure/pcs-config-java","forks_url":"https://api.github.com/repos/Azure/pcs-config-java/forks","keys_url":"https://api.github.com/repos/Azure/pcs-config-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Azure/pcs-config-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Azure/pcs-config-java/teams","hooks_url":"https://api.github.com/repos/Azure/pcs-config-java/hooks","issue_events_url":"https://api.github.com/repos/Azure/pcs-config-java/issues/events{/number}","events_url":"https://api.github.com/repos/Azure/pcs-config-java/events","assignees_url":"https://api.github.com/repos/Azure/pcs-config-java/assignees{/user}","branches_url":"https://api.github.com/repos/Azure/pcs-config-java/branches{/branch}","tags_url":"https://api.github.com/repos/Azure/pcs-config-java/tags","blobs_url":"https://api.github.com/repos/Azure/pcs-config-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Azure/pcs-config-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Azure/pcs-config-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/Azure/pcs-config-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Azure/pcs-config-java/statuses/{sha}","languages_url":"https://api.github.com/repos/Azure/pcs-config-java/languages","stargazers_url":"https://api.github.com/repos/Azure/pcs-config-java/stargazers","contributors_url":"https://api.github.com/repos/Azure/pcs-config-java/contributors","subscribers_url":"https://api.github.com/repos/Azure/pcs-config-java/subscribers","subscription_url":"https://api.github.com/repos/Azure/pcs-config-java/subscription","commits_url":"https://api.github.com/repos/Azure/pcs-config-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/Azure/pcs-config-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/Azure/pcs-config-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/Azure/pcs-config-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/Azure/pcs-config-java/contents/{+path}","compare_url":"https://api.github.com/repos/Azure/pcs-config-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Azure/pcs-config-java/merges","archive_url":"https://api.github.com/repos/Azure/pcs-config-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Azure/pcs-config-java/downloads","issues_url":"https://api.github.com/repos/Azure/pcs-config-java/issues{/number}","pulls_url":"https://api.github.com/repos/Azure/pcs-config-java/pulls{/number}","milestones_url":"https://api.github.com/repos/Azure/pcs-config-java/milestones{/number}","notifications_url":"https://api.github.com/repos/Azure/pcs-config-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Azure/pcs-config-java/labels{/name}","releases_url":"https://api.github.com/repos/Azure/pcs-config-java/releases{/id}","deployments_url":"https://api.github.com/repos/Azure/pcs-config-java/deployments","created_at":"2017-07-05T02:37:33Z","updated_at":"2018-05-02T23:54:28Z","pushed_at":"2018-05-03T02:18:45Z","git_url":"git://github.com/Azure/pcs-config-java.git","ssh_url":"git@github.com:Azure/pcs-config-java.git","clone_url":"https://github.com/Azure/pcs-config-java.git","svn_url":"https://github.com/Azure/pcs-config-java","homepage":"","size":1284,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":7,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":3,"open_issues":7,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Azure/pcs-config-java/pulls/73"},"html":{"href":"https://github.com/Azure/pcs-config-java/pull/73"},"issue":{"href":"https://api.github.com/repos/Azure/pcs-config-java/issues/73"},"comments":{"href":"https://api.github.com/repos/Azure/pcs-config-java/issues/73/comments"},"review_comments":{"href":"https://api.github.com/repos/Azure/pcs-config-java/pulls/73/comments"},"review_comment":{"href":"https://api.github.com/repos/Azure/pcs-config-java/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Azure/pcs-config-java/pulls/73/commits"},"statuses":{"href":"https://api.github.com/repos/Azure/pcs-config-java/statuses/0005d733278493dbf8f19c89ae7a442ac8002401"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"avanikp"}}