{"action":"created","comment":{"url":"https://api.github.com/repos/exceptionless/Exceptionless/pulls/comments/61469060","id":61469060,"diff_hunk":"@@ -36,18 +39,24 @@ public class CloseInactiveSessionsJob : JobWithLockBase {\n \n                 foreach (var sessionStart in results.Documents) {\n                     var lastActivityUtc = sessionStart.Date.UtcDateTime.AddSeconds((double)sessionStart.Value.GetValueOrDefault());\n-                    if (lastActivityUtc > inactivePeriod)\n+                    var lastHeartbeatActivityUtc = await GetLastHeartbeatActivityUtcAsync(sessionStart).AnyContext();\n+\n+                    if (lastHeartbeatActivityUtc.HasValue && lastHeartbeatActivityUtc.Value > lastActivityUtc)\n+                        sessionStart.UpdateSessionStart(lastHeartbeatActivityUtc.Value, isSessionEnd: lastHeartbeatActivityUtc.Value <= inactivePeriod);\n+                    else if (lastActivityUtc <= inactivePeriod)\n+                        sessionStart.UpdateSessionStart(lastActivityUtc, isSessionEnd: true);\n+                    else\n                         continue;\n \n-                    sessionStart.UpdateSessionStart(lastActivityUtc, true);\n                     sessionsToUpdate.Add(sessionStart);\n-\n                     Debug.Assert(sessionStart.Value != null && sessionStart.Value >= 0, \"Session start value cannot be a negative number.\");\n                 }\n \n-                if (sessionsToUpdate.Count > 0)\n+                if (sessionsToUpdate.Count > 0) {\n                     await _eventRepository.SaveAsync(sessionsToUpdate).AnyContext();\n-                \n+                    await _cacheClient.RemoveAllAsync(sessionsToUpdate.SelectMany(GetSessionHeartbeatCacheKeys)).AnyContext();","path":"Source/Core/Jobs/CloseInactiveSessionsJob.cs","position":45,"original_position":45,"commit_id":"bc60a361b9a93ba75e75e5d41d09ed37ed4c697e","original_commit_id":"bc60a361b9a93ba75e75e5d41d09ed37ed4c697e","user":{"login":"niemyjski","id":1020579,"avatar_url":"https://avatars.githubusercontent.com/u/1020579?v=3","gravatar_id":"","url":"https://api.github.com/users/niemyjski","html_url":"https://github.com/niemyjski","followers_url":"https://api.github.com/users/niemyjski/followers","following_url":"https://api.github.com/users/niemyjski/following{/other_user}","gists_url":"https://api.github.com/users/niemyjski/gists{/gist_id}","starred_url":"https://api.github.com/users/niemyjski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niemyjski/subscriptions","organizations_url":"https://api.github.com/users/niemyjski/orgs","repos_url":"https://api.github.com/users/niemyjski/repos","events_url":"https://api.github.com/users/niemyjski/events{/privacy}","received_events_url":"https://api.github.com/users/niemyjski/received_events","type":"User","site_admin":false},"body":"This is the only real issue I see. The cache could be updated with a new timestamp and we are throwing it away. The window of time this happens is very very short..","created_at":"2016-04-28T17:32:56Z","updated_at":"2016-04-28T17:32:56Z","html_url":"https://github.com/exceptionless/Exceptionless/pull/227#discussion_r61469060","pull_request_url":"https://api.github.com/repos/exceptionless/Exceptionless/pulls/227","_links":{"self":{"href":"https://api.github.com/repos/exceptionless/Exceptionless/pulls/comments/61469060"},"html":{"href":"https://github.com/exceptionless/Exceptionless/pull/227#discussion_r61469060"},"pull_request":{"href":"https://api.github.com/repos/exceptionless/Exceptionless/pulls/227"}}},"pull_request":{"url":"https://api.github.com/repos/exceptionless/Exceptionless/pulls/227","id":68259244,"html_url":"https://github.com/exceptionless/Exceptionless/pull/227","diff_url":"https://github.com/exceptionless/Exceptionless/pull/227.diff","patch_url":"https://github.com/exceptionless/Exceptionless/pull/227.patch","issue_url":"https://api.github.com/repos/exceptionless/Exceptionless/issues/227","number":227,"state":"open","locked":false,"title":"Added new heartbeat api endpoint","user":{"login":"niemyjski","id":1020579,"avatar_url":"https://avatars.githubusercontent.com/u/1020579?v=3","gravatar_id":"","url":"https://api.github.com/users/niemyjski","html_url":"https://github.com/niemyjski","followers_url":"https://api.github.com/users/niemyjski/followers","following_url":"https://api.github.com/users/niemyjski/following{/other_user}","gists_url":"https://api.github.com/users/niemyjski/gists{/gist_id}","starred_url":"https://api.github.com/users/niemyjski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niemyjski/subscriptions","organizations_url":"https://api.github.com/users/niemyjski/orgs","repos_url":"https://api.github.com/users/niemyjski/repos","events_url":"https://api.github.com/users/niemyjski/events{/privacy}","received_events_url":"https://api.github.com/users/niemyjski/received_events","type":"User","site_admin":false},"body":"This adds new api fire and forget end point for sending heartbeats.\r\n\r\n@ejsmith do you think we should decrease the job time and inactive session period from 10 minutes to something smaller so things run more often?","created_at":"2016-04-28T17:29:41Z","updated_at":"2016-04-28T17:32:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"18490f6859d84b43cffecc09e2997181090a986e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/exceptionless/Exceptionless/pulls/227/commits","review_comments_url":"https://api.github.com/repos/exceptionless/Exceptionless/pulls/227/comments","review_comment_url":"https://api.github.com/repos/exceptionless/Exceptionless/pulls/comments{/number}","comments_url":"https://api.github.com/repos/exceptionless/Exceptionless/issues/227/comments","statuses_url":"https://api.github.com/repos/exceptionless/Exceptionless/statuses/bc60a361b9a93ba75e75e5d41d09ed37ed4c697e","head":{"label":"exceptionless:feature/heartbeats","ref":"feature/heartbeats","sha":"bc60a361b9a93ba75e75e5d41d09ed37ed4c697e","user":{"login":"exceptionless","id":5912469,"avatar_url":"https://avatars.githubusercontent.com/u/5912469?v=3","gravatar_id":"","url":"https://api.github.com/users/exceptionless","html_url":"https://github.com/exceptionless","followers_url":"https://api.github.com/users/exceptionless/followers","following_url":"https://api.github.com/users/exceptionless/following{/other_user}","gists_url":"https://api.github.com/users/exceptionless/gists{/gist_id}","starred_url":"https://api.github.com/users/exceptionless/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/exceptionless/subscriptions","organizations_url":"https://api.github.com/users/exceptionless/orgs","repos_url":"https://api.github.com/users/exceptionless/repos","events_url":"https://api.github.com/users/exceptionless/events{/privacy}","received_events_url":"https://api.github.com/users/exceptionless/received_events","type":"Organization","site_admin":false},"repo":{"id":16599849,"name":"Exceptionless","full_name":"exceptionless/Exceptionless","owner":{"login":"exceptionless","id":5912469,"avatar_url":"https://avatars.githubusercontent.com/u/5912469?v=3","gravatar_id":"","url":"https://api.github.com/users/exceptionless","html_url":"https://github.com/exceptionless","followers_url":"https://api.github.com/users/exceptionless/followers","following_url":"https://api.github.com/users/exceptionless/following{/other_user}","gists_url":"https://api.github.com/users/exceptionless/gists{/gist_id}","starred_url":"https://api.github.com/users/exceptionless/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/exceptionless/subscriptions","organizations_url":"https://api.github.com/users/exceptionless/orgs","repos_url":"https://api.github.com/users/exceptionless/repos","events_url":"https://api.github.com/users/exceptionless/events{/privacy}","received_events_url":"https://api.github.com/users/exceptionless/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/exceptionless/Exceptionless","description":"Exceptionless server and jobs","fork":false,"url":"https://api.github.com/repos/exceptionless/Exceptionless","forks_url":"https://api.github.com/repos/exceptionless/Exceptionless/forks","keys_url":"https://api.github.com/repos/exceptionless/Exceptionless/keys{/key_id}","collaborators_url":"https://api.github.com/repos/exceptionless/Exceptionless/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/exceptionless/Exceptionless/teams","hooks_url":"https://api.github.com/repos/exceptionless/Exceptionless/hooks","issue_events_url":"https://api.github.com/repos/exceptionless/Exceptionless/issues/events{/number}","events_url":"https://api.github.com/repos/exceptionless/Exceptionless/events","assignees_url":"https://api.github.com/repos/exceptionless/Exceptionless/assignees{/user}","branches_url":"https://api.github.com/repos/exceptionless/Exceptionless/branches{/branch}","tags_url":"https://api.github.com/repos/exceptionless/Exceptionless/tags","blobs_url":"https://api.github.com/repos/exceptionless/Exceptionless/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/exceptionless/Exceptionless/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/exceptionless/Exceptionless/git/refs{/sha}","trees_url":"https://api.github.com/repos/exceptionless/Exceptionless/git/trees{/sha}","statuses_url":"https://api.github.com/repos/exceptionless/Exceptionless/statuses/{sha}","languages_url":"https://api.github.com/repos/exceptionless/Exceptionless/languages","stargazers_url":"https://api.github.com/repos/exceptionless/Exceptionless/stargazers","contributors_url":"https://api.github.com/repos/exceptionless/Exceptionless/contributors","subscribers_url":"https://api.github.com/repos/exceptionless/Exceptionless/subscribers","subscription_url":"https://api.github.com/repos/exceptionless/Exceptionless/subscription","commits_url":"https://api.github.com/repos/exceptionless/Exceptionless/commits{/sha}","git_commits_url":"https://api.github.com/repos/exceptionless/Exceptionless/git/commits{/sha}","comments_url":"https://api.github.com/repos/exceptionless/Exceptionless/comments{/number}","issue_comment_url":"https://api.github.com/repos/exceptionless/Exceptionless/issues/comments{/number}","contents_url":"https://api.github.com/repos/exceptionless/Exceptionless/contents/{+path}","compare_url":"https://api.github.com/repos/exceptionless/Exceptionless/compare/{base}...{head}","merges_url":"https://api.github.com/repos/exceptionless/Exceptionless/merges","archive_url":"https://api.github.com/repos/exceptionless/Exceptionless/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/exceptionless/Exceptionless/downloads","issues_url":"https://api.github.com/repos/exceptionless/Exceptionless/issues{/number}","pulls_url":"https://api.github.com/repos/exceptionless/Exceptionless/pulls{/number}","milestones_url":"https://api.github.com/repos/exceptionless/Exceptionless/milestones{/number}","notifications_url":"https://api.github.com/repos/exceptionless/Exceptionless/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/exceptionless/Exceptionless/labels{/name}","releases_url":"https://api.github.com/repos/exceptionless/Exceptionless/releases{/id}","deployments_url":"https://api.github.com/repos/exceptionless/Exceptionless/deployments","created_at":"2014-02-07T00:48:37Z","updated_at":"2016-04-27T11:15:45Z","pushed_at":"2016-04-28T17:29:43Z","git_url":"git://github.com/exceptionless/Exceptionless.git","ssh_url":"git@github.com:exceptionless/Exceptionless.git","clone_url":"https://github.com/exceptionless/Exceptionless.git","svn_url":"https://github.com/exceptionless/Exceptionless","homepage":"http://exceptionless.com","size":75873,"stargazers_count":452,"watchers_count":452,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":153,"mirror_url":null,"open_issues_count":20,"forks":153,"open_issues":20,"watchers":452,"default_branch":"master"}},"base":{"label":"exceptionless:master","ref":"master","sha":"e6922fcdb108f48b7f58a3703246e9c168c09909","user":{"login":"exceptionless","id":5912469,"avatar_url":"https://avatars.githubusercontent.com/u/5912469?v=3","gravatar_id":"","url":"https://api.github.com/users/exceptionless","html_url":"https://github.com/exceptionless","followers_url":"https://api.github.com/users/exceptionless/followers","following_url":"https://api.github.com/users/exceptionless/following{/other_user}","gists_url":"https://api.github.com/users/exceptionless/gists{/gist_id}","starred_url":"https://api.github.com/users/exceptionless/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/exceptionless/subscriptions","organizations_url":"https://api.github.com/users/exceptionless/orgs","repos_url":"https://api.github.com/users/exceptionless/repos","events_url":"https://api.github.com/users/exceptionless/events{/privacy}","received_events_url":"https://api.github.com/users/exceptionless/received_events","type":"Organization","site_admin":false},"repo":{"id":16599849,"name":"Exceptionless","full_name":"exceptionless/Exceptionless","owner":{"login":"exceptionless","id":5912469,"avatar_url":"https://avatars.githubusercontent.com/u/5912469?v=3","gravatar_id":"","url":"https://api.github.com/users/exceptionless","html_url":"https://github.com/exceptionless","followers_url":"https://api.github.com/users/exceptionless/followers","following_url":"https://api.github.com/users/exceptionless/following{/other_user}","gists_url":"https://api.github.com/users/exceptionless/gists{/gist_id}","starred_url":"https://api.github.com/users/exceptionless/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/exceptionless/subscriptions","organizations_url":"https://api.github.com/users/exceptionless/orgs","repos_url":"https://api.github.com/users/exceptionless/repos","events_url":"https://api.github.com/users/exceptionless/events{/privacy}","received_events_url":"https://api.github.com/users/exceptionless/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/exceptionless/Exceptionless","description":"Exceptionless server and jobs","fork":false,"url":"https://api.github.com/repos/exceptionless/Exceptionless","forks_url":"https://api.github.com/repos/exceptionless/Exceptionless/forks","keys_url":"https://api.github.com/repos/exceptionless/Exceptionless/keys{/key_id}","collaborators_url":"https://api.github.com/repos/exceptionless/Exceptionless/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/exceptionless/Exceptionless/teams","hooks_url":"https://api.github.com/repos/exceptionless/Exceptionless/hooks","issue_events_url":"https://api.github.com/repos/exceptionless/Exceptionless/issues/events{/number}","events_url":"https://api.github.com/repos/exceptionless/Exceptionless/events","assignees_url":"https://api.github.com/repos/exceptionless/Exceptionless/assignees{/user}","branches_url":"https://api.github.com/repos/exceptionless/Exceptionless/branches{/branch}","tags_url":"https://api.github.com/repos/exceptionless/Exceptionless/tags","blobs_url":"https://api.github.com/repos/exceptionless/Exceptionless/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/exceptionless/Exceptionless/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/exceptionless/Exceptionless/git/refs{/sha}","trees_url":"https://api.github.com/repos/exceptionless/Exceptionless/git/trees{/sha}","statuses_url":"https://api.github.com/repos/exceptionless/Exceptionless/statuses/{sha}","languages_url":"https://api.github.com/repos/exceptionless/Exceptionless/languages","stargazers_url":"https://api.github.com/repos/exceptionless/Exceptionless/stargazers","contributors_url":"https://api.github.com/repos/exceptionless/Exceptionless/contributors","subscribers_url":"https://api.github.com/repos/exceptionless/Exceptionless/subscribers","subscription_url":"https://api.github.com/repos/exceptionless/Exceptionless/subscription","commits_url":"https://api.github.com/repos/exceptionless/Exceptionless/commits{/sha}","git_commits_url":"https://api.github.com/repos/exceptionless/Exceptionless/git/commits{/sha}","comments_url":"https://api.github.com/repos/exceptionless/Exceptionless/comments{/number}","issue_comment_url":"https://api.github.com/repos/exceptionless/Exceptionless/issues/comments{/number}","contents_url":"https://api.github.com/repos/exceptionless/Exceptionless/contents/{+path}","compare_url":"https://api.github.com/repos/exceptionless/Exceptionless/compare/{base}...{head}","merges_url":"https://api.github.com/repos/exceptionless/Exceptionless/merges","archive_url":"https://api.github.com/repos/exceptionless/Exceptionless/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/exceptionless/Exceptionless/downloads","issues_url":"https://api.github.com/repos/exceptionless/Exceptionless/issues{/number}","pulls_url":"https://api.github.com/repos/exceptionless/Exceptionless/pulls{/number}","milestones_url":"https://api.github.com/repos/exceptionless/Exceptionless/milestones{/number}","notifications_url":"https://api.github.com/repos/exceptionless/Exceptionless/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/exceptionless/Exceptionless/labels{/name}","releases_url":"https://api.github.com/repos/exceptionless/Exceptionless/releases{/id}","deployments_url":"https://api.github.com/repos/exceptionless/Exceptionless/deployments","created_at":"2014-02-07T00:48:37Z","updated_at":"2016-04-27T11:15:45Z","pushed_at":"2016-04-28T17:29:43Z","git_url":"git://github.com/exceptionless/Exceptionless.git","ssh_url":"git@github.com:exceptionless/Exceptionless.git","clone_url":"https://github.com/exceptionless/Exceptionless.git","svn_url":"https://github.com/exceptionless/Exceptionless","homepage":"http://exceptionless.com","size":75873,"stargazers_count":452,"watchers_count":452,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":153,"mirror_url":null,"open_issues_count":20,"forks":153,"open_issues":20,"watchers":452,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/exceptionless/Exceptionless/pulls/227"},"html":{"href":"https://github.com/exceptionless/Exceptionless/pull/227"},"issue":{"href":"https://api.github.com/repos/exceptionless/Exceptionless/issues/227"},"comments":{"href":"https://api.github.com/repos/exceptionless/Exceptionless/issues/227/comments"},"review_comments":{"href":"https://api.github.com/repos/exceptionless/Exceptionless/pulls/227/comments"},"review_comment":{"href":"https://api.github.com/repos/exceptionless/Exceptionless/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/exceptionless/Exceptionless/pulls/227/commits"},"statuses":{"href":"https://api.github.com/repos/exceptionless/Exceptionless/statuses/bc60a361b9a93ba75e75e5d41d09ed37ed4c697e"}}}}