{"action":"created","comment":{"url":"https://api.github.com/repos/strands-project/strands_apps/pulls/comments/31910140","id":31910140,"diff_hunk":"@@ -0,0 +1,74 @@\n+import yaml\n+from monitors import MonitorType\n+from actions import ActionType\n+from threading import Timer, Lock\n+import rospy\n+\n+class Watchdog(object):\n+    yaml_keys = ['name', 'description', 'restart_timeout', 'monitors', 'actions']\n+    def __init__(self, config):\n+        if not isinstance(config,  dict):\n+            raise Exception(\"Watchdog class must be created with dictionary \"\n+                            \"as parameter.\")\n+        for key in self.yaml_keys:\n+            if key not in config:\n+                raise Exception(\"YAML config error: monitor/action pair \"\n+                                \"missing '{}' field\".format(key))\n+\n+        self._name = config['name']\n+        self._restart_timeout =  config['restart_timeout']\n+        self._restart_timer =  None\n+        self._monitors = []\n+        self._executing = Lock()\n+        for monitor in config['monitors']:\n+            self._monitors.append(MonitorType.create(monitor, self.execute))\n+        self._actions = []\n+        for action in config['actions']:\n+            self._actions.append(ActionType.create(action))\n+        \n+    \n+    def _start_monitors(self):\n+        for monitor in self._monitors:\n+            monitor.start()\n+            \n+    def _stop_monitors(self, restart_after_timeout=False):\n+        for monitor in self._monitors:\n+            monitor.stop()\n+            \n+    def _check(self):\n+        for monitor in self._monitors:\n+            if monitor.check():\n+                return True\n+        return False\n+    \n+    def _execute(self):\n+        rospy.logwarn(\"Executing '{}' watchdog.\".format(self._name))\n+        self.shutdown()","path":"watchdog/src/watchdog/watchdog.py","position":46,"original_position":46,"commit_id":"6766100c69c70bf29e038bf400901e8b8b362262","original_commit_id":"6766100c69c70bf29e038bf400901e8b8b362262","user":{"login":"cburbridge","id":259580,"avatar_url":"https://avatars.githubusercontent.com/u/259580?v=3","gravatar_id":"","url":"https://api.github.com/users/cburbridge","html_url":"https://github.com/cburbridge","followers_url":"https://api.github.com/users/cburbridge/followers","following_url":"https://api.github.com/users/cburbridge/following{/other_user}","gists_url":"https://api.github.com/users/cburbridge/gists{/gist_id}","starred_url":"https://api.github.com/users/cburbridge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cburbridge/subscriptions","organizations_url":"https://api.github.com/users/cburbridge/orgs","repos_url":"https://api.github.com/users/cburbridge/repos","events_url":"https://api.github.com/users/cburbridge/events{/privacy}","received_events_url":"https://api.github.com/users/cburbridge/received_events","type":"User","site_admin":false},"body":"It restarts after the time stated in the YAML file. This is needed, for example if a monitor fires because a node is not doing something for 5 seconds, but that node doesn't do something until 10s after launch, then the monitor will repeat fire. ","created_at":"2015-06-08T12:48:52Z","updated_at":"2015-06-08T12:48:52Z","html_url":"https://github.com/strands-project/strands_apps/pull/43#discussion_r31910140","pull_request_url":"https://api.github.com/repos/strands-project/strands_apps/pulls/43","_links":{"self":{"href":"https://api.github.com/repos/strands-project/strands_apps/pulls/comments/31910140"},"html":{"href":"https://github.com/strands-project/strands_apps/pull/43#discussion_r31910140"},"pull_request":{"href":"https://api.github.com/repos/strands-project/strands_apps/pulls/43"}}},"pull_request":{"url":"https://api.github.com/repos/strands-project/strands_apps/pulls/43","id":36710526,"html_url":"https://github.com/strands-project/strands_apps/pull/43","diff_url":"https://github.com/strands-project/strands_apps/pull/43.diff","patch_url":"https://github.com/strands-project/strands_apps/pull/43.patch","issue_url":"https://api.github.com/repos/strands-project/strands_apps/issues/43","number":43,"state":"open","locked":false,"title":"watchdog package","user":{"login":"cburbridge","id":259580,"avatar_url":"https://avatars.githubusercontent.com/u/259580?v=3","gravatar_id":"","url":"https://api.github.com/users/cburbridge","html_url":"https://github.com/cburbridge","followers_url":"https://api.github.com/users/cburbridge/followers","following_url":"https://api.github.com/users/cburbridge/following{/other_user}","gists_url":"https://api.github.com/users/cburbridge/gists{/gist_id}","starred_url":"https://api.github.com/users/cburbridge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cburbridge/subscriptions","organizations_url":"https://api.github.com/users/cburbridge/orgs","repos_url":"https://api.github.com/users/cburbridge/repos","events_url":"https://api.github.com/users/cburbridge/events{/privacy}","received_events_url":"https://api.github.com/users/cburbridge/received_events","type":"User","site_admin":false},"body":"This PR adds a new 'watchdog' package as described in the readme: https://github.com/cburbridge/strands_apps/blob/indigo-devel/watchdog/README.md\r\n","created_at":"2015-06-02T09:42:31Z","updated_at":"2015-06-08T12:48:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0b804df9e48b226ff8ce90bdc5f572246ce1ef88","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/strands-project/strands_apps/pulls/43/commits","review_comments_url":"https://api.github.com/repos/strands-project/strands_apps/pulls/43/comments","review_comment_url":"https://api.github.com/repos/strands-project/strands_apps/pulls/comments{/number}","comments_url":"https://api.github.com/repos/strands-project/strands_apps/issues/43/comments","statuses_url":"https://api.github.com/repos/strands-project/strands_apps/statuses/6766100c69c70bf29e038bf400901e8b8b362262","head":{"label":"cburbridge:indigo-devel","ref":"indigo-devel","sha":"6766100c69c70bf29e038bf400901e8b8b362262","user":{"login":"cburbridge","id":259580,"avatar_url":"https://avatars.githubusercontent.com/u/259580?v=3","gravatar_id":"","url":"https://api.github.com/users/cburbridge","html_url":"https://github.com/cburbridge","followers_url":"https://api.github.com/users/cburbridge/followers","following_url":"https://api.github.com/users/cburbridge/following{/other_user}","gists_url":"https://api.github.com/users/cburbridge/gists{/gist_id}","starred_url":"https://api.github.com/users/cburbridge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cburbridge/subscriptions","organizations_url":"https://api.github.com/users/cburbridge/orgs","repos_url":"https://api.github.com/users/cburbridge/repos","events_url":"https://api.github.com/users/cburbridge/events{/privacy}","received_events_url":"https://api.github.com/users/cburbridge/received_events","type":"User","site_admin":false},"repo":{"id":26804961,"name":"strands_apps","full_name":"cburbridge/strands_apps","owner":{"login":"cburbridge","id":259580,"avatar_url":"https://avatars.githubusercontent.com/u/259580?v=3","gravatar_id":"","url":"https://api.github.com/users/cburbridge","html_url":"https://github.com/cburbridge","followers_url":"https://api.github.com/users/cburbridge/followers","following_url":"https://api.github.com/users/cburbridge/following{/other_user}","gists_url":"https://api.github.com/users/cburbridge/gists{/gist_id}","starred_url":"https://api.github.com/users/cburbridge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cburbridge/subscriptions","organizations_url":"https://api.github.com/users/cburbridge/orgs","repos_url":"https://api.github.com/users/cburbridge/repos","events_url":"https://api.github.com/users/cburbridge/events{/privacy}","received_events_url":"https://api.github.com/users/cburbridge/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cburbridge/strands_apps","description":"Project specific apps and tools","fork":true,"url":"https://api.github.com/repos/cburbridge/strands_apps","forks_url":"https://api.github.com/repos/cburbridge/strands_apps/forks","keys_url":"https://api.github.com/repos/cburbridge/strands_apps/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cburbridge/strands_apps/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cburbridge/strands_apps/teams","hooks_url":"https://api.github.com/repos/cburbridge/strands_apps/hooks","issue_events_url":"https://api.github.com/repos/cburbridge/strands_apps/issues/events{/number}","events_url":"https://api.github.com/repos/cburbridge/strands_apps/events","assignees_url":"https://api.github.com/repos/cburbridge/strands_apps/assignees{/user}","branches_url":"https://api.github.com/repos/cburbridge/strands_apps/branches{/branch}","tags_url":"https://api.github.com/repos/cburbridge/strands_apps/tags","blobs_url":"https://api.github.com/repos/cburbridge/strands_apps/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cburbridge/strands_apps/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cburbridge/strands_apps/git/refs{/sha}","trees_url":"https://api.github.com/repos/cburbridge/strands_apps/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cburbridge/strands_apps/statuses/{sha}","languages_url":"https://api.github.com/repos/cburbridge/strands_apps/languages","stargazers_url":"https://api.github.com/repos/cburbridge/strands_apps/stargazers","contributors_url":"https://api.github.com/repos/cburbridge/strands_apps/contributors","subscribers_url":"https://api.github.com/repos/cburbridge/strands_apps/subscribers","subscription_url":"https://api.github.com/repos/cburbridge/strands_apps/subscription","commits_url":"https://api.github.com/repos/cburbridge/strands_apps/commits{/sha}","git_commits_url":"https://api.github.com/repos/cburbridge/strands_apps/git/commits{/sha}","comments_url":"https://api.github.com/repos/cburbridge/strands_apps/comments{/number}","issue_comment_url":"https://api.github.com/repos/cburbridge/strands_apps/issues/comments{/number}","contents_url":"https://api.github.com/repos/cburbridge/strands_apps/contents/{+path}","compare_url":"https://api.github.com/repos/cburbridge/strands_apps/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cburbridge/strands_apps/merges","archive_url":"https://api.github.com/repos/cburbridge/strands_apps/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cburbridge/strands_apps/downloads","issues_url":"https://api.github.com/repos/cburbridge/strands_apps/issues{/number}","pulls_url":"https://api.github.com/repos/cburbridge/strands_apps/pulls{/number}","milestones_url":"https://api.github.com/repos/cburbridge/strands_apps/milestones{/number}","notifications_url":"https://api.github.com/repos/cburbridge/strands_apps/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cburbridge/strands_apps/labels{/name}","releases_url":"https://api.github.com/repos/cburbridge/strands_apps/releases{/id}","created_at":"2014-11-18T10:55:14Z","updated_at":"2015-04-01T13:04:23Z","pushed_at":"2015-06-02T09:45:56Z","git_url":"git://github.com/cburbridge/strands_apps.git","ssh_url":"git@github.com:cburbridge/strands_apps.git","clone_url":"https://github.com/cburbridge/strands_apps.git","svn_url":"https://github.com/cburbridge/strands_apps","homepage":null,"size":618,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"hydro-devel"}},"base":{"label":"strands-project:indigo-devel","ref":"indigo-devel","sha":"576561677ad4581fd69f8e673dca93356261f75c","user":{"login":"strands-project","id":3989374,"avatar_url":"https://avatars.githubusercontent.com/u/3989374?v=3","gravatar_id":"","url":"https://api.github.com/users/strands-project","html_url":"https://github.com/strands-project","followers_url":"https://api.github.com/users/strands-project/followers","following_url":"https://api.github.com/users/strands-project/following{/other_user}","gists_url":"https://api.github.com/users/strands-project/gists{/gist_id}","starred_url":"https://api.github.com/users/strands-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/strands-project/subscriptions","organizations_url":"https://api.github.com/users/strands-project/orgs","repos_url":"https://api.github.com/users/strands-project/repos","events_url":"https://api.github.com/users/strands-project/events{/privacy}","received_events_url":"https://api.github.com/users/strands-project/received_events","type":"Organization","site_admin":false},"repo":{"id":23587002,"name":"strands_apps","full_name":"strands-project/strands_apps","owner":{"login":"strands-project","id":3989374,"avatar_url":"https://avatars.githubusercontent.com/u/3989374?v=3","gravatar_id":"","url":"https://api.github.com/users/strands-project","html_url":"https://github.com/strands-project","followers_url":"https://api.github.com/users/strands-project/followers","following_url":"https://api.github.com/users/strands-project/following{/other_user}","gists_url":"https://api.github.com/users/strands-project/gists{/gist_id}","starred_url":"https://api.github.com/users/strands-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/strands-project/subscriptions","organizations_url":"https://api.github.com/users/strands-project/orgs","repos_url":"https://api.github.com/users/strands-project/repos","events_url":"https://api.github.com/users/strands-project/events{/privacy}","received_events_url":"https://api.github.com/users/strands-project/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/strands-project/strands_apps","description":"Project specific apps and tools","fork":false,"url":"https://api.github.com/repos/strands-project/strands_apps","forks_url":"https://api.github.com/repos/strands-project/strands_apps/forks","keys_url":"https://api.github.com/repos/strands-project/strands_apps/keys{/key_id}","collaborators_url":"https://api.github.com/repos/strands-project/strands_apps/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/strands-project/strands_apps/teams","hooks_url":"https://api.github.com/repos/strands-project/strands_apps/hooks","issue_events_url":"https://api.github.com/repos/strands-project/strands_apps/issues/events{/number}","events_url":"https://api.github.com/repos/strands-project/strands_apps/events","assignees_url":"https://api.github.com/repos/strands-project/strands_apps/assignees{/user}","branches_url":"https://api.github.com/repos/strands-project/strands_apps/branches{/branch}","tags_url":"https://api.github.com/repos/strands-project/strands_apps/tags","blobs_url":"https://api.github.com/repos/strands-project/strands_apps/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/strands-project/strands_apps/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/strands-project/strands_apps/git/refs{/sha}","trees_url":"https://api.github.com/repos/strands-project/strands_apps/git/trees{/sha}","statuses_url":"https://api.github.com/repos/strands-project/strands_apps/statuses/{sha}","languages_url":"https://api.github.com/repos/strands-project/strands_apps/languages","stargazers_url":"https://api.github.com/repos/strands-project/strands_apps/stargazers","contributors_url":"https://api.github.com/repos/strands-project/strands_apps/contributors","subscribers_url":"https://api.github.com/repos/strands-project/strands_apps/subscribers","subscription_url":"https://api.github.com/repos/strands-project/strands_apps/subscription","commits_url":"https://api.github.com/repos/strands-project/strands_apps/commits{/sha}","git_commits_url":"https://api.github.com/repos/strands-project/strands_apps/git/commits{/sha}","comments_url":"https://api.github.com/repos/strands-project/strands_apps/comments{/number}","issue_comment_url":"https://api.github.com/repos/strands-project/strands_apps/issues/comments{/number}","contents_url":"https://api.github.com/repos/strands-project/strands_apps/contents/{+path}","compare_url":"https://api.github.com/repos/strands-project/strands_apps/compare/{base}...{head}","merges_url":"https://api.github.com/repos/strands-project/strands_apps/merges","archive_url":"https://api.github.com/repos/strands-project/strands_apps/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/strands-project/strands_apps/downloads","issues_url":"https://api.github.com/repos/strands-project/strands_apps/issues{/number}","pulls_url":"https://api.github.com/repos/strands-project/strands_apps/pulls{/number}","milestones_url":"https://api.github.com/repos/strands-project/strands_apps/milestones{/number}","notifications_url":"https://api.github.com/repos/strands-project/strands_apps/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/strands-project/strands_apps/labels{/name}","releases_url":"https://api.github.com/repos/strands-project/strands_apps/releases{/id}","created_at":"2014-09-02T16:49:05Z","updated_at":"2015-04-28T14:59:36Z","pushed_at":"2015-06-02T09:45:57Z","git_url":"git://github.com/strands-project/strands_apps.git","ssh_url":"git@github.com:strands-project/strands_apps.git","clone_url":"https://github.com/strands-project/strands_apps.git","svn_url":"https://github.com/strands-project/strands_apps","homepage":null,"size":896,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":8,"mirror_url":null,"open_issues_count":4,"forks":8,"open_issues":4,"watchers":0,"default_branch":"indigo-devel"}},"_links":{"self":{"href":"https://api.github.com/repos/strands-project/strands_apps/pulls/43"},"html":{"href":"https://github.com/strands-project/strands_apps/pull/43"},"issue":{"href":"https://api.github.com/repos/strands-project/strands_apps/issues/43"},"comments":{"href":"https://api.github.com/repos/strands-project/strands_apps/issues/43/comments"},"review_comments":{"href":"https://api.github.com/repos/strands-project/strands_apps/pulls/43/comments"},"review_comment":{"href":"https://api.github.com/repos/strands-project/strands_apps/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/strands-project/strands_apps/pulls/43/commits"},"statuses":{"href":"https://api.github.com/repos/strands-project/strands_apps/statuses/6766100c69c70bf29e038bf400901e8b8b362262"}}}}