{"action":"created","comment":{"url":"https://api.github.com/repos/hashicorp/nomad/pulls/comments/57492795","id":57492795,"diff_hunk":"@@ -0,0 +1,87 @@\n+package consul\n+\n+import (\n+\t\"log\"\n+\t\"math/rand\"\n+\t\"sync\"\n+\t\"time\"\n+\n+\tcstructs \"github.com/hashicorp/nomad/client/driver/structs\"\n+)\n+\n+// CheckRunner runs a given check in a specific interval and update a\n+// corresponding Consul TTL check\n+type CheckRunner struct {\n+\tcheck    Check\n+\trunCheck func(Check)\n+\tlogger   *log.Logger\n+\tstop     bool\n+\tstopCh   chan struct{}\n+\tstopLock sync.Mutex\n+\n+\tstarted     bool\n+\tstartedLock sync.Mutex\n+}\n+\n+// NewCheckRunner configures and returns a CheckRunner\n+func NewCheckRunner(check Check, runCheck func(Check), logger *log.Logger) *CheckRunner {\n+\tcr := CheckRunner{\n+\t\tcheck:    check,\n+\t\trunCheck: runCheck,\n+\t\tlogger:   logger,\n+\t\tstopCh:   make(chan struct{}),\n+\t}\n+\treturn &cr\n+}\n+\n+// Start is used to start the check. The check runs until stop is called\n+func (r *CheckRunner) Start() {\n+\tr.startedLock.Lock()\n+\tdefer r.startedLock.Unlock()\n+\tif r.started {\n+\t\treturn\n+\t}\n+\tr.stopLock.Lock()\n+\tdefer r.stopLock.Unlock()\n+\tgo r.run()\n+\tr.started = true\n+}\n+\n+// Stop is used to stop the check.\n+func (r *CheckRunner) Stop() {\n+\tr.stopLock.Lock()\n+\tdefer r.stopLock.Unlock()\n+\tif !r.stop {\n+\t\tr.stop = true\n+\t\tclose(r.stopCh)\n+\t}\n+}\n+\n+// run is invoked by a goroutine to run until Stop() is called\n+func (r *CheckRunner) run() {\n+\t// Get the randomized initial pause time\n+\tinitialPauseTime := randomStagger(r.check.Interval())\n+\tr.logger.Printf(\"[DEBUG] agent: pausing %v before first invocation of %s\", initialPauseTime, r.check.ID())\n+\tnext := time.After(initialPauseTime)\n+\tfor {\n+\t\tselect {\n+\t\tcase <-next:\n+\t\t\tr.runCheck(r.check)\n+\t\t\tnext = time.After(r.check.Interval())","path":"client/consul/check.go","position":70,"original_position":70,"commit_id":"f8db6a433f8b4d8e811182bd93b789cab8cf4d8d","original_commit_id":"4c2766085a636042d0a971fd89bb89010972f627","user":{"login":"diptanu","id":21833,"avatar_url":"https://avatars.githubusercontent.com/u/21833?v=3","gravatar_id":"","url":"https://api.github.com/users/diptanu","html_url":"https://github.com/diptanu","followers_url":"https://api.github.com/users/diptanu/followers","following_url":"https://api.github.com/users/diptanu/following{/other_user}","gists_url":"https://api.github.com/users/diptanu/gists{/gist_id}","starred_url":"https://api.github.com/users/diptanu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diptanu/subscriptions","organizations_url":"https://api.github.com/users/diptanu/orgs","repos_url":"https://api.github.com/users/diptanu/repos","events_url":"https://api.github.com/users/diptanu/events{/privacy}","received_events_url":"https://api.github.com/users/diptanu/received_events","type":"User","site_admin":false},"body":"@dadgar Can't use a single timer or ticker here since we are sleeping for a different duration for the first time, and from then onwards sleeping for the duration of the check interval.","created_at":"2016-03-25T21:23:46Z","updated_at":"2016-03-25T21:23:46Z","html_url":"https://github.com/hashicorp/nomad/pull/986#discussion_r57492795","pull_request_url":"https://api.github.com/repos/hashicorp/nomad/pulls/986","_links":{"self":{"href":"https://api.github.com/repos/hashicorp/nomad/pulls/comments/57492795"},"html":{"href":"https://github.com/hashicorp/nomad/pull/986#discussion_r57492795"},"pull_request":{"href":"https://api.github.com/repos/hashicorp/nomad/pulls/986"}}},"pull_request":{"url":"https://api.github.com/repos/hashicorp/nomad/pulls/986","id":64124156,"html_url":"https://github.com/hashicorp/nomad/pull/986","diff_url":"https://github.com/hashicorp/nomad/pull/986.diff","patch_url":"https://github.com/hashicorp/nomad/pull/986.patch","issue_url":"https://api.github.com/repos/hashicorp/nomad/issues/986","number":986,"state":"open","locked":false,"title":"Implement script checks","user":{"login":"diptanu","id":21833,"avatar_url":"https://avatars.githubusercontent.com/u/21833?v=3","gravatar_id":"","url":"https://api.github.com/users/diptanu","html_url":"https://github.com/diptanu","followers_url":"https://api.github.com/users/diptanu/followers","following_url":"https://api.github.com/users/diptanu/following{/other_user}","gists_url":"https://api.github.com/users/diptanu/gists{/gist_id}","starred_url":"https://api.github.com/users/diptanu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diptanu/subscriptions","organizations_url":"https://api.github.com/users/diptanu/orgs","repos_url":"https://api.github.com/users/diptanu/repos","events_url":"https://api.github.com/users/diptanu/events{/privacy}","received_events_url":"https://api.github.com/users/diptanu/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-03-25T02:20:00Z","updated_at":"2016-03-25T21:23:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f4b9f31258b12250f8d2592c351efd62d834bd8c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/hashicorp/nomad/pulls/986/commits","review_comments_url":"https://api.github.com/repos/hashicorp/nomad/pulls/986/comments","review_comment_url":"https://api.github.com/repos/hashicorp/nomad/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hashicorp/nomad/issues/986/comments","statuses_url":"https://api.github.com/repos/hashicorp/nomad/statuses/f8db6a433f8b4d8e811182bd93b789cab8cf4d8d","head":{"label":"hashicorp:scripts","ref":"scripts","sha":"f8db6a433f8b4d8e811182bd93b789cab8cf4d8d","user":{"login":"hashicorp","id":761456,"avatar_url":"https://avatars.githubusercontent.com/u/761456?v=3","gravatar_id":"","url":"https://api.github.com/users/hashicorp","html_url":"https://github.com/hashicorp","followers_url":"https://api.github.com/users/hashicorp/followers","following_url":"https://api.github.com/users/hashicorp/following{/other_user}","gists_url":"https://api.github.com/users/hashicorp/gists{/gist_id}","starred_url":"https://api.github.com/users/hashicorp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hashicorp/subscriptions","organizations_url":"https://api.github.com/users/hashicorp/orgs","repos_url":"https://api.github.com/users/hashicorp/repos","events_url":"https://api.github.com/users/hashicorp/events{/privacy}","received_events_url":"https://api.github.com/users/hashicorp/received_events","type":"Organization","site_admin":false},"repo":{"id":36653430,"name":"nomad","full_name":"hashicorp/nomad","owner":{"login":"hashicorp","id":761456,"avatar_url":"https://avatars.githubusercontent.com/u/761456?v=3","gravatar_id":"","url":"https://api.github.com/users/hashicorp","html_url":"https://github.com/hashicorp","followers_url":"https://api.github.com/users/hashicorp/followers","following_url":"https://api.github.com/users/hashicorp/following{/other_user}","gists_url":"https://api.github.com/users/hashicorp/gists{/gist_id}","starred_url":"https://api.github.com/users/hashicorp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hashicorp/subscriptions","organizations_url":"https://api.github.com/users/hashicorp/orgs","repos_url":"https://api.github.com/users/hashicorp/repos","events_url":"https://api.github.com/users/hashicorp/events{/privacy}","received_events_url":"https://api.github.com/users/hashicorp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hashicorp/nomad","description":"A Distributed, Highly Available, Datacenter-Aware Scheduler","fork":false,"url":"https://api.github.com/repos/hashicorp/nomad","forks_url":"https://api.github.com/repos/hashicorp/nomad/forks","keys_url":"https://api.github.com/repos/hashicorp/nomad/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hashicorp/nomad/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hashicorp/nomad/teams","hooks_url":"https://api.github.com/repos/hashicorp/nomad/hooks","issue_events_url":"https://api.github.com/repos/hashicorp/nomad/issues/events{/number}","events_url":"https://api.github.com/repos/hashicorp/nomad/events","assignees_url":"https://api.github.com/repos/hashicorp/nomad/assignees{/user}","branches_url":"https://api.github.com/repos/hashicorp/nomad/branches{/branch}","tags_url":"https://api.github.com/repos/hashicorp/nomad/tags","blobs_url":"https://api.github.com/repos/hashicorp/nomad/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hashicorp/nomad/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hashicorp/nomad/git/refs{/sha}","trees_url":"https://api.github.com/repos/hashicorp/nomad/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hashicorp/nomad/statuses/{sha}","languages_url":"https://api.github.com/repos/hashicorp/nomad/languages","stargazers_url":"https://api.github.com/repos/hashicorp/nomad/stargazers","contributors_url":"https://api.github.com/repos/hashicorp/nomad/contributors","subscribers_url":"https://api.github.com/repos/hashicorp/nomad/subscribers","subscription_url":"https://api.github.com/repos/hashicorp/nomad/subscription","commits_url":"https://api.github.com/repos/hashicorp/nomad/commits{/sha}","git_commits_url":"https://api.github.com/repos/hashicorp/nomad/git/commits{/sha}","comments_url":"https://api.github.com/repos/hashicorp/nomad/comments{/number}","issue_comment_url":"https://api.github.com/repos/hashicorp/nomad/issues/comments{/number}","contents_url":"https://api.github.com/repos/hashicorp/nomad/contents/{+path}","compare_url":"https://api.github.com/repos/hashicorp/nomad/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hashicorp/nomad/merges","archive_url":"https://api.github.com/repos/hashicorp/nomad/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hashicorp/nomad/downloads","issues_url":"https://api.github.com/repos/hashicorp/nomad/issues{/number}","pulls_url":"https://api.github.com/repos/hashicorp/nomad/pulls{/number}","milestones_url":"https://api.github.com/repos/hashicorp/nomad/milestones{/number}","notifications_url":"https://api.github.com/repos/hashicorp/nomad/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hashicorp/nomad/labels{/name}","releases_url":"https://api.github.com/repos/hashicorp/nomad/releases{/id}","deployments_url":"https://api.github.com/repos/hashicorp/nomad/deployments","created_at":"2015-06-01T10:21:00Z","updated_at":"2016-03-25T13:49:52Z","pushed_at":"2016-03-25T21:18:17Z","git_url":"git://github.com/hashicorp/nomad.git","ssh_url":"git@github.com:hashicorp/nomad.git","clone_url":"https://github.com/hashicorp/nomad.git","svn_url":"https://github.com/hashicorp/nomad","homepage":"https://www.nomadproject.io/","size":23186,"stargazers_count":1440,"watchers_count":1440,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":184,"mirror_url":null,"open_issues_count":86,"forks":184,"open_issues":86,"watchers":1440,"default_branch":"master"}},"base":{"label":"hashicorp:master","ref":"master","sha":"36346c02444794d531144450ed5d1a141cae9b2e","user":{"login":"hashicorp","id":761456,"avatar_url":"https://avatars.githubusercontent.com/u/761456?v=3","gravatar_id":"","url":"https://api.github.com/users/hashicorp","html_url":"https://github.com/hashicorp","followers_url":"https://api.github.com/users/hashicorp/followers","following_url":"https://api.github.com/users/hashicorp/following{/other_user}","gists_url":"https://api.github.com/users/hashicorp/gists{/gist_id}","starred_url":"https://api.github.com/users/hashicorp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hashicorp/subscriptions","organizations_url":"https://api.github.com/users/hashicorp/orgs","repos_url":"https://api.github.com/users/hashicorp/repos","events_url":"https://api.github.com/users/hashicorp/events{/privacy}","received_events_url":"https://api.github.com/users/hashicorp/received_events","type":"Organization","site_admin":false},"repo":{"id":36653430,"name":"nomad","full_name":"hashicorp/nomad","owner":{"login":"hashicorp","id":761456,"avatar_url":"https://avatars.githubusercontent.com/u/761456?v=3","gravatar_id":"","url":"https://api.github.com/users/hashicorp","html_url":"https://github.com/hashicorp","followers_url":"https://api.github.com/users/hashicorp/followers","following_url":"https://api.github.com/users/hashicorp/following{/other_user}","gists_url":"https://api.github.com/users/hashicorp/gists{/gist_id}","starred_url":"https://api.github.com/users/hashicorp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hashicorp/subscriptions","organizations_url":"https://api.github.com/users/hashicorp/orgs","repos_url":"https://api.github.com/users/hashicorp/repos","events_url":"https://api.github.com/users/hashicorp/events{/privacy}","received_events_url":"https://api.github.com/users/hashicorp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hashicorp/nomad","description":"A Distributed, Highly Available, Datacenter-Aware Scheduler","fork":false,"url":"https://api.github.com/repos/hashicorp/nomad","forks_url":"https://api.github.com/repos/hashicorp/nomad/forks","keys_url":"https://api.github.com/repos/hashicorp/nomad/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hashicorp/nomad/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hashicorp/nomad/teams","hooks_url":"https://api.github.com/repos/hashicorp/nomad/hooks","issue_events_url":"https://api.github.com/repos/hashicorp/nomad/issues/events{/number}","events_url":"https://api.github.com/repos/hashicorp/nomad/events","assignees_url":"https://api.github.com/repos/hashicorp/nomad/assignees{/user}","branches_url":"https://api.github.com/repos/hashicorp/nomad/branches{/branch}","tags_url":"https://api.github.com/repos/hashicorp/nomad/tags","blobs_url":"https://api.github.com/repos/hashicorp/nomad/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hashicorp/nomad/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hashicorp/nomad/git/refs{/sha}","trees_url":"https://api.github.com/repos/hashicorp/nomad/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hashicorp/nomad/statuses/{sha}","languages_url":"https://api.github.com/repos/hashicorp/nomad/languages","stargazers_url":"https://api.github.com/repos/hashicorp/nomad/stargazers","contributors_url":"https://api.github.com/repos/hashicorp/nomad/contributors","subscribers_url":"https://api.github.com/repos/hashicorp/nomad/subscribers","subscription_url":"https://api.github.com/repos/hashicorp/nomad/subscription","commits_url":"https://api.github.com/repos/hashicorp/nomad/commits{/sha}","git_commits_url":"https://api.github.com/repos/hashicorp/nomad/git/commits{/sha}","comments_url":"https://api.github.com/repos/hashicorp/nomad/comments{/number}","issue_comment_url":"https://api.github.com/repos/hashicorp/nomad/issues/comments{/number}","contents_url":"https://api.github.com/repos/hashicorp/nomad/contents/{+path}","compare_url":"https://api.github.com/repos/hashicorp/nomad/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hashicorp/nomad/merges","archive_url":"https://api.github.com/repos/hashicorp/nomad/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hashicorp/nomad/downloads","issues_url":"https://api.github.com/repos/hashicorp/nomad/issues{/number}","pulls_url":"https://api.github.com/repos/hashicorp/nomad/pulls{/number}","milestones_url":"https://api.github.com/repos/hashicorp/nomad/milestones{/number}","notifications_url":"https://api.github.com/repos/hashicorp/nomad/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hashicorp/nomad/labels{/name}","releases_url":"https://api.github.com/repos/hashicorp/nomad/releases{/id}","deployments_url":"https://api.github.com/repos/hashicorp/nomad/deployments","created_at":"2015-06-01T10:21:00Z","updated_at":"2016-03-25T13:49:52Z","pushed_at":"2016-03-25T21:18:17Z","git_url":"git://github.com/hashicorp/nomad.git","ssh_url":"git@github.com:hashicorp/nomad.git","clone_url":"https://github.com/hashicorp/nomad.git","svn_url":"https://github.com/hashicorp/nomad","homepage":"https://www.nomadproject.io/","size":23186,"stargazers_count":1440,"watchers_count":1440,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":184,"mirror_url":null,"open_issues_count":86,"forks":184,"open_issues":86,"watchers":1440,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hashicorp/nomad/pulls/986"},"html":{"href":"https://github.com/hashicorp/nomad/pull/986"},"issue":{"href":"https://api.github.com/repos/hashicorp/nomad/issues/986"},"comments":{"href":"https://api.github.com/repos/hashicorp/nomad/issues/986/comments"},"review_comments":{"href":"https://api.github.com/repos/hashicorp/nomad/pulls/986/comments"},"review_comment":{"href":"https://api.github.com/repos/hashicorp/nomad/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hashicorp/nomad/pulls/986/commits"},"statuses":{"href":"https://api.github.com/repos/hashicorp/nomad/statuses/f8db6a433f8b4d8e811182bd93b789cab8cf4d8d"}}}}