{"action":"created","comment":{"url":"https://api.github.com/repos/sensu/sensu/pulls/comments/98828242","pull_request_review_id":19482339,"id":98828242,"diff_hunk":"@@ -683,6 +684,45 @@ def calculate_check_execution_splay(check)\n         (splay_hash - current_time) % (check[:interval] * 1000) / 1000.0\n       end\n \n+      # The use of a Timer to implement cron like this is slightly problematic\n+      # in that if you are testing on yur laptop for example, and you close the\n+      # lid after the next check is scheduled, and you open it back up, the scheduled\n+      # check will still execute 'x' seconds from the original calculated 'fire' time\n+      # even if that time has already passed. So watch out for that.\n+      # \n+      # @param cron_expression [String] The cron expression you want to use.\n+      # @param check [Hash] definition.\n+      # @param create_check_request [block] reference to block to execute on next cron fire.\n+      def schedule_cron(check, &create_check_request)\n+        cron_expression = check[:cron]\n+        @logger.debug(\"Scheduling next cron tick for\", :check => check)\n+        cron_parser = CronParser.new(cron_expression)\n+        now = Time.now\n+        @logger.debug(\"It is now: #{now}\")\n+        next_time = cron_parser.next(now)\n+        @logger.debug(\"Next scheduled run is: #{next_time}\")\n+        time_difference = next_time - now\n+        @logger.debug(\"Time difference is: #{time_difference}\")\n+        @timers[:leader] << EM::Timer.new(time_difference) do\n+          create_check_request.call\n+          schedule_cron(check, &create_check_request)\n+        end\n+      end\n+\n+      # The block that creates the check request once the EM timer fires.\n+      #\n+      # @param check [Hash] definition.\n+      def get_check_request_block(check)\n+        create_check_request = Proc.new do\n+            unless check_request_subdued?(check)\n+              publish_check_request(check)\n+            else\n+              @logger.info(\"check request was subdued\", :check => check)\n+            end","path":"lib/sensu/server/process.rb","position":46,"original_position":46,"commit_id":"ac73d260de53c7d6e9e3982f9bc5dc6cceb7eefe","original_commit_id":"ac73d260de53c7d6e9e3982f9bc5dc6cceb7eefe","user":{"login":"baweaver","id":979723,"avatar_url":"https://avatars.githubusercontent.com/u/979723?v=3","gravatar_id":"","url":"https://api.github.com/users/baweaver","html_url":"https://github.com/baweaver","followers_url":"https://api.github.com/users/baweaver/followers","following_url":"https://api.github.com/users/baweaver/following{/other_user}","gists_url":"https://api.github.com/users/baweaver/gists{/gist_id}","starred_url":"https://api.github.com/users/baweaver/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/baweaver/subscriptions","organizations_url":"https://api.github.com/users/baweaver/orgs","repos_url":"https://api.github.com/users/baweaver/repos","events_url":"https://api.github.com/users/baweaver/events{/privacy}","received_events_url":"https://api.github.com/users/baweaver/received_events","type":"User","site_admin":false},"body":"Odd indentation, but nitpick","created_at":"2017-02-01T04:51:05Z","updated_at":"2017-02-01T04:51:05Z","html_url":"https://github.com/sensu/sensu/pull/1397#discussion_r98828242","pull_request_url":"https://api.github.com/repos/sensu/sensu/pulls/1397","_links":{"self":{"href":"https://api.github.com/repos/sensu/sensu/pulls/comments/98828242"},"html":{"href":"https://github.com/sensu/sensu/pull/1397#discussion_r98828242"},"pull_request":{"href":"https://api.github.com/repos/sensu/sensu/pulls/1397"}}},"pull_request":{"url":"https://api.github.com/repos/sensu/sensu/pulls/1397","id":79453215,"html_url":"https://github.com/sensu/sensu/pull/1397","diff_url":"https://github.com/sensu/sensu/pull/1397.diff","patch_url":"https://github.com/sensu/sensu/pull/1397.patch","issue_url":"https://api.github.com/repos/sensu/sensu/issues/1397","number":1397,"state":"open","locked":false,"title":"Add cron to sensu","user":{"login":"chriszacny","id":5723606,"avatar_url":"https://avatars.githubusercontent.com/u/5723606?v=3","gravatar_id":"","url":"https://api.github.com/users/chriszacny","html_url":"https://github.com/chriszacny","followers_url":"https://api.github.com/users/chriszacny/followers","following_url":"https://api.github.com/users/chriszacny/following{/other_user}","gists_url":"https://api.github.com/users/chriszacny/gists{/gist_id}","starred_url":"https://api.github.com/users/chriszacny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chriszacny/subscriptions","organizations_url":"https://api.github.com/users/chriszacny/orgs","repos_url":"https://api.github.com/users/chriszacny/repos","events_url":"https://api.github.com/users/chriszacny/events{/privacy}","received_events_url":"https://api.github.com/users/chriszacny/received_events","type":"User","site_admin":false},"body":"Hi folks,\n\nThis is a relatively simple add of the \"cron\" attribute; it enables cron expressions that effectively override the \"interval\" attribute on a check. I've found this very useful for several of our batch checks that need to run at very specific times in house. Unless I'm missing a way to do this using interval.\n\nI'd be happy to tidy this up as needed (for example, \"interval\" is still required on a check even if you specify \"cron\"); or simply request that this be added as a feature in a future release.\n\nThanks!\n","created_at":"2016-07-30T09:38:45Z","updated_at":"2017-02-01T04:51:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0e09d5adaaf0221138a9beee6ca0173d361b4fd7","assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/sensu/sensu/milestones/5","html_url":"https://github.com/sensu/sensu/milestone/5","labels_url":"https://api.github.com/repos/sensu/sensu/milestones/5/labels","id":1886453,"number":5,"title":"0.28","description":"","creator":{"login":"cwjohnston","id":148017,"avatar_url":"https://avatars.githubusercontent.com/u/148017?v=3","gravatar_id":"","url":"https://api.github.com/users/cwjohnston","html_url":"https://github.com/cwjohnston","followers_url":"https://api.github.com/users/cwjohnston/followers","following_url":"https://api.github.com/users/cwjohnston/following{/other_user}","gists_url":"https://api.github.com/users/cwjohnston/gists{/gist_id}","starred_url":"https://api.github.com/users/cwjohnston/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cwjohnston/subscriptions","organizations_url":"https://api.github.com/users/cwjohnston/orgs","repos_url":"https://api.github.com/users/cwjohnston/repos","events_url":"https://api.github.com/users/cwjohnston/events{/privacy}","received_events_url":"https://api.github.com/users/cwjohnston/received_events","type":"User","site_admin":false},"open_issues":32,"closed_issues":3,"state":"open","created_at":"2016-07-15T19:01:44Z","updated_at":"2017-01-31T20:03:40Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/sensu/sensu/pulls/1397/commits","review_comments_url":"https://api.github.com/repos/sensu/sensu/pulls/1397/comments","review_comment_url":"https://api.github.com/repos/sensu/sensu/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sensu/sensu/issues/1397/comments","statuses_url":"https://api.github.com/repos/sensu/sensu/statuses/ac73d260de53c7d6e9e3982f9bc5dc6cceb7eefe","head":{"label":"chriszacny:add_cron_to_sensu","ref":"add_cron_to_sensu","sha":"ac73d260de53c7d6e9e3982f9bc5dc6cceb7eefe","user":{"login":"chriszacny","id":5723606,"avatar_url":"https://avatars.githubusercontent.com/u/5723606?v=3","gravatar_id":"","url":"https://api.github.com/users/chriszacny","html_url":"https://github.com/chriszacny","followers_url":"https://api.github.com/users/chriszacny/followers","following_url":"https://api.github.com/users/chriszacny/following{/other_user}","gists_url":"https://api.github.com/users/chriszacny/gists{/gist_id}","starred_url":"https://api.github.com/users/chriszacny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chriszacny/subscriptions","organizations_url":"https://api.github.com/users/chriszacny/orgs","repos_url":"https://api.github.com/users/chriszacny/repos","events_url":"https://api.github.com/users/chriszacny/events{/privacy}","received_events_url":"https://api.github.com/users/chriszacny/received_events","type":"User","site_admin":false},"repo":{"id":63442257,"name":"sensu","full_name":"chriszacny/sensu","owner":{"login":"chriszacny","id":5723606,"avatar_url":"https://avatars.githubusercontent.com/u/5723606?v=3","gravatar_id":"","url":"https://api.github.com/users/chriszacny","html_url":"https://github.com/chriszacny","followers_url":"https://api.github.com/users/chriszacny/followers","following_url":"https://api.github.com/users/chriszacny/following{/other_user}","gists_url":"https://api.github.com/users/chriszacny/gists{/gist_id}","starred_url":"https://api.github.com/users/chriszacny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chriszacny/subscriptions","organizations_url":"https://api.github.com/users/chriszacny/orgs","repos_url":"https://api.github.com/users/chriszacny/repos","events_url":"https://api.github.com/users/chriszacny/events{/privacy}","received_events_url":"https://api.github.com/users/chriszacny/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/chriszacny/sensu","description":"Monitoring for today's infrastructure. ","fork":true,"url":"https://api.github.com/repos/chriszacny/sensu","forks_url":"https://api.github.com/repos/chriszacny/sensu/forks","keys_url":"https://api.github.com/repos/chriszacny/sensu/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chriszacny/sensu/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chriszacny/sensu/teams","hooks_url":"https://api.github.com/repos/chriszacny/sensu/hooks","issue_events_url":"https://api.github.com/repos/chriszacny/sensu/issues/events{/number}","events_url":"https://api.github.com/repos/chriszacny/sensu/events","assignees_url":"https://api.github.com/repos/chriszacny/sensu/assignees{/user}","branches_url":"https://api.github.com/repos/chriszacny/sensu/branches{/branch}","tags_url":"https://api.github.com/repos/chriszacny/sensu/tags","blobs_url":"https://api.github.com/repos/chriszacny/sensu/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chriszacny/sensu/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chriszacny/sensu/git/refs{/sha}","trees_url":"https://api.github.com/repos/chriszacny/sensu/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chriszacny/sensu/statuses/{sha}","languages_url":"https://api.github.com/repos/chriszacny/sensu/languages","stargazers_url":"https://api.github.com/repos/chriszacny/sensu/stargazers","contributors_url":"https://api.github.com/repos/chriszacny/sensu/contributors","subscribers_url":"https://api.github.com/repos/chriszacny/sensu/subscribers","subscription_url":"https://api.github.com/repos/chriszacny/sensu/subscription","commits_url":"https://api.github.com/repos/chriszacny/sensu/commits{/sha}","git_commits_url":"https://api.github.com/repos/chriszacny/sensu/git/commits{/sha}","comments_url":"https://api.github.com/repos/chriszacny/sensu/comments{/number}","issue_comment_url":"https://api.github.com/repos/chriszacny/sensu/issues/comments{/number}","contents_url":"https://api.github.com/repos/chriszacny/sensu/contents/{+path}","compare_url":"https://api.github.com/repos/chriszacny/sensu/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chriszacny/sensu/merges","archive_url":"https://api.github.com/repos/chriszacny/sensu/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chriszacny/sensu/downloads","issues_url":"https://api.github.com/repos/chriszacny/sensu/issues{/number}","pulls_url":"https://api.github.com/repos/chriszacny/sensu/pulls{/number}","milestones_url":"https://api.github.com/repos/chriszacny/sensu/milestones{/number}","notifications_url":"https://api.github.com/repos/chriszacny/sensu/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chriszacny/sensu/labels{/name}","releases_url":"https://api.github.com/repos/chriszacny/sensu/releases{/id}","deployments_url":"https://api.github.com/repos/chriszacny/sensu/deployments","created_at":"2016-07-15T18:17:52Z","updated_at":"2016-07-15T18:17:54Z","pushed_at":"2016-07-30T09:51:24Z","git_url":"git://github.com/chriszacny/sensu.git","ssh_url":"git@github.com:chriszacny/sensu.git","clone_url":"https://github.com/chriszacny/sensu.git","svn_url":"https://github.com/chriszacny/sensu","homepage":"https://sensuapp.org","size":3229,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"sensu:master","ref":"master","sha":"ed6d091178960417aaaeec8ceb191995ba27b88a","user":{"login":"sensu","id":1648901,"avatar_url":"https://avatars.githubusercontent.com/u/1648901?v=3","gravatar_id":"","url":"https://api.github.com/users/sensu","html_url":"https://github.com/sensu","followers_url":"https://api.github.com/users/sensu/followers","following_url":"https://api.github.com/users/sensu/following{/other_user}","gists_url":"https://api.github.com/users/sensu/gists{/gist_id}","starred_url":"https://api.github.com/users/sensu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sensu/subscriptions","organizations_url":"https://api.github.com/users/sensu/orgs","repos_url":"https://api.github.com/users/sensu/repos","events_url":"https://api.github.com/users/sensu/events{/privacy}","received_events_url":"https://api.github.com/users/sensu/received_events","type":"Organization","site_admin":false},"repo":{"id":2031640,"name":"sensu","full_name":"sensu/sensu","owner":{"login":"sensu","id":1648901,"avatar_url":"https://avatars.githubusercontent.com/u/1648901?v=3","gravatar_id":"","url":"https://api.github.com/users/sensu","html_url":"https://github.com/sensu","followers_url":"https://api.github.com/users/sensu/followers","following_url":"https://api.github.com/users/sensu/following{/other_user}","gists_url":"https://api.github.com/users/sensu/gists{/gist_id}","starred_url":"https://api.github.com/users/sensu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sensu/subscriptions","organizations_url":"https://api.github.com/users/sensu/orgs","repos_url":"https://api.github.com/users/sensu/repos","events_url":"https://api.github.com/users/sensu/events{/privacy}","received_events_url":"https://api.github.com/users/sensu/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sensu/sensu","description":"Monitoring for today's infrastructure. ","fork":false,"url":"https://api.github.com/repos/sensu/sensu","forks_url":"https://api.github.com/repos/sensu/sensu/forks","keys_url":"https://api.github.com/repos/sensu/sensu/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sensu/sensu/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sensu/sensu/teams","hooks_url":"https://api.github.com/repos/sensu/sensu/hooks","issue_events_url":"https://api.github.com/repos/sensu/sensu/issues/events{/number}","events_url":"https://api.github.com/repos/sensu/sensu/events","assignees_url":"https://api.github.com/repos/sensu/sensu/assignees{/user}","branches_url":"https://api.github.com/repos/sensu/sensu/branches{/branch}","tags_url":"https://api.github.com/repos/sensu/sensu/tags","blobs_url":"https://api.github.com/repos/sensu/sensu/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sensu/sensu/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sensu/sensu/git/refs{/sha}","trees_url":"https://api.github.com/repos/sensu/sensu/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sensu/sensu/statuses/{sha}","languages_url":"https://api.github.com/repos/sensu/sensu/languages","stargazers_url":"https://api.github.com/repos/sensu/sensu/stargazers","contributors_url":"https://api.github.com/repos/sensu/sensu/contributors","subscribers_url":"https://api.github.com/repos/sensu/sensu/subscribers","subscription_url":"https://api.github.com/repos/sensu/sensu/subscription","commits_url":"https://api.github.com/repos/sensu/sensu/commits{/sha}","git_commits_url":"https://api.github.com/repos/sensu/sensu/git/commits{/sha}","comments_url":"https://api.github.com/repos/sensu/sensu/comments{/number}","issue_comment_url":"https://api.github.com/repos/sensu/sensu/issues/comments{/number}","contents_url":"https://api.github.com/repos/sensu/sensu/contents/{+path}","compare_url":"https://api.github.com/repos/sensu/sensu/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sensu/sensu/merges","archive_url":"https://api.github.com/repos/sensu/sensu/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sensu/sensu/downloads","issues_url":"https://api.github.com/repos/sensu/sensu/issues{/number}","pulls_url":"https://api.github.com/repos/sensu/sensu/pulls{/number}","milestones_url":"https://api.github.com/repos/sensu/sensu/milestones{/number}","notifications_url":"https://api.github.com/repos/sensu/sensu/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sensu/sensu/labels{/name}","releases_url":"https://api.github.com/repos/sensu/sensu/releases{/id}","deployments_url":"https://api.github.com/repos/sensu/sensu/deployments","created_at":"2011-07-11T17:50:16Z","updated_at":"2017-01-31T19:46:05Z","pushed_at":"2017-01-31T19:59:46Z","git_url":"git://github.com/sensu/sensu.git","ssh_url":"git@github.com:sensu/sensu.git","clone_url":"https://github.com/sensu/sensu.git","svn_url":"https://github.com/sensu/sensu","homepage":"https://sensuapp.org","size":3292,"stargazers_count":2542,"watchers_count":2542,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":355,"mirror_url":null,"open_issues_count":114,"forks":355,"open_issues":114,"watchers":2542,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sensu/sensu/pulls/1397"},"html":{"href":"https://github.com/sensu/sensu/pull/1397"},"issue":{"href":"https://api.github.com/repos/sensu/sensu/issues/1397"},"comments":{"href":"https://api.github.com/repos/sensu/sensu/issues/1397/comments"},"review_comments":{"href":"https://api.github.com/repos/sensu/sensu/pulls/1397/comments"},"review_comment":{"href":"https://api.github.com/repos/sensu/sensu/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sensu/sensu/pulls/1397/commits"},"statuses":{"href":"https://api.github.com/repos/sensu/sensu/statuses/ac73d260de53c7d6e9e3982f9bc5dc6cceb7eefe"}}}}
{"actor":{"display_login":"baweaver"}}