{"action":"created","comment":{"url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/pulls/comments/37260055","id":37260055,"diff_hunk":"@@ -1,58 +1,127 @@\n #!/usr/bin/python\n import os\n+import sys\n import json\n import time\n+import argparse\n from apscheduler.schedulers.background import BackgroundScheduler\n-# from apscheduler.triggers.inteval import IntervalTrigger\n+from watchdog.observers import Observer\n+from watchdog.events import PatternMatchingEventHandler\n from minions import ShellMinion\n \n \n+class JsonHandler(PatternMatchingEventHandler):\n+    def set_handler(self, oncreated=None, onmodified=None, ondeleted=None):\n+        self.create_handler = oncreated\n+        self.modify_handler = onmodified\n+        self.delete_handler = ondeleted\n+\n+    def on_created(self, event):\n+        self.create_handler(event.src_path)\n+\n+    def on_modified(self, event):\n+        self.modify_handler(event.src_path)\n+\n+    def on_deleted(self, event):\n+        self.delete_handler(event.src_path)\n+\n+\n class Boss(object):\n-    default_path = None\n-    workers = []\n+    workers = {}\n+    dirpath = '.'\n+    output = None\n \n-    def __init__(self):\n+    def __init__(self, dirpath='.', output='output'):\n         '''\n         local path for load config\n         '''\n+        if os.path.isdir(dirpath):\n+            self.dirpath = dirpath\n+        else:\n+            print(dirpath + \" is invalid, use default path instead\")\n+        self.output = output\n+        if not os.path.isdir(output):\n+            print(\"target directory \" + output + \" doesn't exist, creating..\")\n+            os.makedirs(output)\n+\n         self.scheduler = BackgroundScheduler()\n         self.scheduler.start()\n-        if self.default_path:\n-            self.load(self.default_path)\n+\n+        self.load_dir(dirpath)\n+\n+        event_handler = JsonHandler(patterns=[\"*.json\"],\n+                                    ignore_directories=True)\n+        event_handler.set_handler(oncreated=self.load,\n+                                  onmodified=self.load,\n+                                  ondeleted=self.remove)\n+        observer = Observer()\n+        observer.schedule(event_handler, self.dirpath, recursive=True)\n+        observer.start()\n \n     def load_dir(self, folder):\n         (dirpath, dirnames, filenames) = os.walk(folder).next()\n-        for fn in filenames:\n-            self.load(os.path.join(dirpath, fn))\n+        for fname in filenames:\n+            if 'json' in fname[-4:]:\n+                self.load(os.path.join(dirpath, fname))\n \n     def load(self, fp):\n         '''\n-        given a file\n-        TBI: directory\n+        given a json file, load and create a task run regularly\n         '''\n+        # for debugging\n+        print(fp + \" was loaded!\")","path":"moz_minions/boss.py","position":82,"original_position":82,"commit_id":"885ce9651ecb33b1496482f6ea20e4fffa535cf2","original_commit_id":"885ce9651ecb33b1496482f6ea20e4fffa535cf2","user":{"login":"ypwalter","id":2697364,"avatar_url":"https://avatars.githubusercontent.com/u/2697364?v=3","gravatar_id":"","url":"https://api.github.com/users/ypwalter","html_url":"https://github.com/ypwalter","followers_url":"https://api.github.com/users/ypwalter/followers","following_url":"https://api.github.com/users/ypwalter/following{/other_user}","gists_url":"https://api.github.com/users/ypwalter/gists{/gist_id}","starred_url":"https://api.github.com/users/ypwalter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ypwalter/subscriptions","organizations_url":"https://api.github.com/users/ypwalter/orgs","repos_url":"https://api.github.com/users/ypwalter/repos","events_url":"https://api.github.com/users/ypwalter/events{/privacy}","received_events_url":"https://api.github.com/users/ypwalter/received_events","type":"User","site_admin":false},"body":"for debugging?\r\nshould we add a environment variable like \"DEBUG\", and make it prints & logs whenever it is enabled?","created_at":"2015-08-18T02:55:15Z","updated_at":"2015-08-18T02:55:15Z","html_url":"https://github.com/Mozilla-TWQA/mozMinions/pull/3#discussion_r37260055","pull_request_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/pulls/comments/37260055"},"html":{"href":"https://github.com/Mozilla-TWQA/mozMinions/pull/3#discussion_r37260055"},"pull_request":{"href":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/pulls/3","id":42572355,"html_url":"https://github.com/Mozilla-TWQA/mozMinions/pull/3","diff_url":"https://github.com/Mozilla-TWQA/mozMinions/pull/3.diff","patch_url":"https://github.com/Mozilla-TWQA/mozMinions/pull/3.patch","issue_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/issues/3","number":3,"state":"open","locked":false,"title":"file listener support","user":{"login":"zapion","id":734529,"avatar_url":"https://avatars.githubusercontent.com/u/734529?v=3","gravatar_id":"","url":"https://api.github.com/users/zapion","html_url":"https://github.com/zapion","followers_url":"https://api.github.com/users/zapion/followers","following_url":"https://api.github.com/users/zapion/following{/other_user}","gists_url":"https://api.github.com/users/zapion/gists{/gist_id}","starred_url":"https://api.github.com/users/zapion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zapion/subscriptions","organizations_url":"https://api.github.com/users/zapion/orgs","repos_url":"https://api.github.com/users/zapion/repos","events_url":"https://api.github.com/users/zapion/events{/privacy}","received_events_url":"https://api.github.com/users/zapion/received_events","type":"User","site_admin":false},"body":"File listener support:\r\nWhile boss launched, json files in default dir will be loaded and used to create minions.\r\nThen a monitor will be setup to catch json file events.\r\non_created: load json file and create minion\r\non_modified: re-load json file\r\non_deleted: remove job and delete running minion\r\nAdd cmd options:\r\n--dirpath : will load all json files, and then directory is monitored for any json file created/modified/removed\r\n--output : setup a default output directory for storing all report files in\r\n\r\njson file syntax update:\r\n{\"output\" : {\"dirpath\" : \"/tmp/default\", \"file\" : \"report\"}}\r\nwill store reports in \"/tmp/default/report_**timestamp**\"\r\n\r\n**TODO**: Add test for boss.py","created_at":"2015-08-17T10:08:46Z","updated_at":"2015-08-18T02:55:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e1d60a6396b00c7e4786f565f70bd526e87df049","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/pulls/3/commits","review_comments_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/pulls/3/comments","review_comment_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/issues/3/comments","statuses_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/statuses/885ce9651ecb33b1496482f6ea20e4fffa535cf2","head":{"label":"zapion:file_listener_support","ref":"file_listener_support","sha":"885ce9651ecb33b1496482f6ea20e4fffa535cf2","user":{"login":"zapion","id":734529,"avatar_url":"https://avatars.githubusercontent.com/u/734529?v=3","gravatar_id":"","url":"https://api.github.com/users/zapion","html_url":"https://github.com/zapion","followers_url":"https://api.github.com/users/zapion/followers","following_url":"https://api.github.com/users/zapion/following{/other_user}","gists_url":"https://api.github.com/users/zapion/gists{/gist_id}","starred_url":"https://api.github.com/users/zapion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zapion/subscriptions","organizations_url":"https://api.github.com/users/zapion/orgs","repos_url":"https://api.github.com/users/zapion/repos","events_url":"https://api.github.com/users/zapion/events{/privacy}","received_events_url":"https://api.github.com/users/zapion/received_events","type":"User","site_admin":false},"repo":{"id":40645624,"name":"mozMinions","full_name":"zapion/mozMinions","owner":{"login":"zapion","id":734529,"avatar_url":"https://avatars.githubusercontent.com/u/734529?v=3","gravatar_id":"","url":"https://api.github.com/users/zapion","html_url":"https://github.com/zapion","followers_url":"https://api.github.com/users/zapion/followers","following_url":"https://api.github.com/users/zapion/following{/other_user}","gists_url":"https://api.github.com/users/zapion/gists{/gist_id}","starred_url":"https://api.github.com/users/zapion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zapion/subscriptions","organizations_url":"https://api.github.com/users/zapion/orgs","repos_url":"https://api.github.com/users/zapion/repos","events_url":"https://api.github.com/users/zapion/events{/privacy}","received_events_url":"https://api.github.com/users/zapion/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zapion/mozMinions","description":"","fork":true,"url":"https://api.github.com/repos/zapion/mozMinions","forks_url":"https://api.github.com/repos/zapion/mozMinions/forks","keys_url":"https://api.github.com/repos/zapion/mozMinions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zapion/mozMinions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zapion/mozMinions/teams","hooks_url":"https://api.github.com/repos/zapion/mozMinions/hooks","issue_events_url":"https://api.github.com/repos/zapion/mozMinions/issues/events{/number}","events_url":"https://api.github.com/repos/zapion/mozMinions/events","assignees_url":"https://api.github.com/repos/zapion/mozMinions/assignees{/user}","branches_url":"https://api.github.com/repos/zapion/mozMinions/branches{/branch}","tags_url":"https://api.github.com/repos/zapion/mozMinions/tags","blobs_url":"https://api.github.com/repos/zapion/mozMinions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zapion/mozMinions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zapion/mozMinions/git/refs{/sha}","trees_url":"https://api.github.com/repos/zapion/mozMinions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zapion/mozMinions/statuses/{sha}","languages_url":"https://api.github.com/repos/zapion/mozMinions/languages","stargazers_url":"https://api.github.com/repos/zapion/mozMinions/stargazers","contributors_url":"https://api.github.com/repos/zapion/mozMinions/contributors","subscribers_url":"https://api.github.com/repos/zapion/mozMinions/subscribers","subscription_url":"https://api.github.com/repos/zapion/mozMinions/subscription","commits_url":"https://api.github.com/repos/zapion/mozMinions/commits{/sha}","git_commits_url":"https://api.github.com/repos/zapion/mozMinions/git/commits{/sha}","comments_url":"https://api.github.com/repos/zapion/mozMinions/comments{/number}","issue_comment_url":"https://api.github.com/repos/zapion/mozMinions/issues/comments{/number}","contents_url":"https://api.github.com/repos/zapion/mozMinions/contents/{+path}","compare_url":"https://api.github.com/repos/zapion/mozMinions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zapion/mozMinions/merges","archive_url":"https://api.github.com/repos/zapion/mozMinions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zapion/mozMinions/downloads","issues_url":"https://api.github.com/repos/zapion/mozMinions/issues{/number}","pulls_url":"https://api.github.com/repos/zapion/mozMinions/pulls{/number}","milestones_url":"https://api.github.com/repos/zapion/mozMinions/milestones{/number}","notifications_url":"https://api.github.com/repos/zapion/mozMinions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zapion/mozMinions/labels{/name}","releases_url":"https://api.github.com/repos/zapion/mozMinions/releases{/id}","created_at":"2015-08-13T07:43:26Z","updated_at":"2015-08-13T07:43:27Z","pushed_at":"2015-08-17T14:41:57Z","git_url":"git://github.com/zapion/mozMinions.git","ssh_url":"git@github.com:zapion/mozMinions.git","clone_url":"https://github.com/zapion/mozMinions.git","svn_url":"https://github.com/zapion/mozMinions","homepage":null,"size":0,"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":"master"}},"base":{"label":"Mozilla-TWQA:master","ref":"master","sha":"7ae7ba9fd487ca0b8a4e954e8df40dbc941e1f9d","user":{"login":"Mozilla-TWQA","id":3487714,"avatar_url":"https://avatars.githubusercontent.com/u/3487714?v=3","gravatar_id":"","url":"https://api.github.com/users/Mozilla-TWQA","html_url":"https://github.com/Mozilla-TWQA","followers_url":"https://api.github.com/users/Mozilla-TWQA/followers","following_url":"https://api.github.com/users/Mozilla-TWQA/following{/other_user}","gists_url":"https://api.github.com/users/Mozilla-TWQA/gists{/gist_id}","starred_url":"https://api.github.com/users/Mozilla-TWQA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mozilla-TWQA/subscriptions","organizations_url":"https://api.github.com/users/Mozilla-TWQA/orgs","repos_url":"https://api.github.com/users/Mozilla-TWQA/repos","events_url":"https://api.github.com/users/Mozilla-TWQA/events{/privacy}","received_events_url":"https://api.github.com/users/Mozilla-TWQA/received_events","type":"Organization","site_admin":false},"repo":{"id":40584642,"name":"mozMinions","full_name":"Mozilla-TWQA/mozMinions","owner":{"login":"Mozilla-TWQA","id":3487714,"avatar_url":"https://avatars.githubusercontent.com/u/3487714?v=3","gravatar_id":"","url":"https://api.github.com/users/Mozilla-TWQA","html_url":"https://github.com/Mozilla-TWQA","followers_url":"https://api.github.com/users/Mozilla-TWQA/followers","following_url":"https://api.github.com/users/Mozilla-TWQA/following{/other_user}","gists_url":"https://api.github.com/users/Mozilla-TWQA/gists{/gist_id}","starred_url":"https://api.github.com/users/Mozilla-TWQA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mozilla-TWQA/subscriptions","organizations_url":"https://api.github.com/users/Mozilla-TWQA/orgs","repos_url":"https://api.github.com/users/Mozilla-TWQA/repos","events_url":"https://api.github.com/users/Mozilla-TWQA/events{/privacy}","received_events_url":"https://api.github.com/users/Mozilla-TWQA/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Mozilla-TWQA/mozMinions","description":"","fork":false,"url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions","forks_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/forks","keys_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/teams","hooks_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/hooks","issue_events_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/issues/events{/number}","events_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/events","assignees_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/assignees{/user}","branches_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/branches{/branch}","tags_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/tags","blobs_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/git/refs{/sha}","trees_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/statuses/{sha}","languages_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/languages","stargazers_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/stargazers","contributors_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/contributors","subscribers_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/subscribers","subscription_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/subscription","commits_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/commits{/sha}","git_commits_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/git/commits{/sha}","comments_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/comments{/number}","issue_comment_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/issues/comments{/number}","contents_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/contents/{+path}","compare_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/merges","archive_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/downloads","issues_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/issues{/number}","pulls_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/pulls{/number}","milestones_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/milestones{/number}","notifications_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/labels{/name}","releases_url":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/releases{/id}","created_at":"2015-08-12T06:43:02Z","updated_at":"2015-08-12T06:45:00Z","pushed_at":"2015-08-17T10:08:46Z","git_url":"git://github.com/Mozilla-TWQA/mozMinions.git","ssh_url":"git@github.com:Mozilla-TWQA/mozMinions.git","clone_url":"https://github.com/Mozilla-TWQA/mozMinions.git","svn_url":"https://github.com/Mozilla-TWQA/mozMinions","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":1,"forks":3,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/pulls/3"},"html":{"href":"https://github.com/Mozilla-TWQA/mozMinions/pull/3"},"issue":{"href":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/issues/3"},"comments":{"href":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/Mozilla-TWQA/mozMinions/statuses/885ce9651ecb33b1496482f6ea20e4fffa535cf2"}}}}