GitHub PullRequestReviewCommentEvent at 2014-12-16 11:20:10
Repository: runbot-addons
Actor: gurneyalex
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/OCA/runbot-addons/pulls/comments/21891296","id":21891296,"diff_hunk":"@@ -0,0 +1,154 @@\n+# -*- encoding: utf-8 -*-\n+##############################################################################\n+#\n+#    Odoo, Open Source Management Solution\n+#    This module copyright (C) 2010 - 2014 Savoir-faire Linux\n+#    (<http://www.savoirfairelinux.com>).\n+#\n+#    This program is free software: you can redistribute it and/or modify\n+#    it under the terms of the GNU Affero General Public License as\n+#    published by the Free Software Foundation, either version 3 of the\n+#    License, or (at your option) any later version.\n+#\n+#    This program is distributed in the hope that it will be useful,\n+#    but WITHOUT ANY WARRANTY; without even the implied warranty of\n+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+#    GNU Affero General Public License for more details.\n+#\n+#    You should have received a copy of the GNU Affero General Public License\n+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n+#\n+##############################################################################\n+\n+import os\n+import shutil\n+import re\n+import pwd\n+import time\n+import psutil\n+import signal\n+\n+from contextlib import closing\n+\n+import logging\n+_logger = logging.getLogger(__name__)\n+\n+from openerp import models, api, SUPERUSER_ID, tools, sql_db\n+\n+\n+def exp_list_posix_user():\n+    \"\"\"Rewrite/simplified version of openerp.service.exp_list()\n+    Lists all databases owned by the current posix user instead of the db_user\n+    from odoo config.\n+    The reason for this is because runbot creates databases with the posix\n+    user.\n+    :returns list of databases owned by the posix user\n+    \"\"\"\n+    chosen_template = tools.config['db_template']\n+    templates_list = {'template0', 'template1', 'postgres', chosen_template}\n+    db = sql_db.db_connect('postgres')\n+    with closing(db.cursor()) as cr:\n+        db_user = pwd.getpwuid(os.getuid())[0]\n+        cr.execute(\"\"\"\n+SELECT datname\n+FROM pg_database\n+WHERE datdba=(\n+    SELECT usesysid\n+    FROM pg_user\n+    WHERE usename=%s\n+) AND datname NOT IN %s order by datname\"\"\", (db_user, tuple(templates_list)))\n+        res = [tools.ustr(name) for (name,) in cr.fetchall()]\n+    res.sort()\n+    return res\n+\n+\n+class RunbotRepo(models.Model):\n+    \"\"\"Aggressively clean filesystem databases and processes.\"\"\"\n+    _inherit = \"runbot.repo\"\n+\n+    def __init__(self, pool, cr):\n+        \"\"\"On reinitialisation of db, mark all builds as done\"\"\"\n+        super(RunbotRepo, self).__init__(pool, cr)\n+        runbot_build = pool['runbot.build']\n+        ids = pool['runbot.build'].search(cr, SUPERUSER_ID, [])\n+        runbot_build.write(cr, SUPERUSER_ID, ids, {'state': 'done'})\n+\n+    @api.model\n+    def cron(self):\n+        \"\"\"Overcharge cron, add clean up subroutine before the general cron.\"\"\"\n+        self.clean_up()\n+        return super(RunbotRepo, self).cron()\n+\n+    def clean_up(self):\n+        \"\"\"Examines the build directory, identify leftover builds then\n+        call the cleans: filesystem, database, process\n+\n+        Leftover builds will have state done\n+        Skip if the build directory hasn't been created yet\n+        \"\"\"\n+        self.clean_up_pids()\n+        build_root = os.path.join(self.root(), 'build')\n+        if not os.path.exists(build_root):\n+            return\n+        build_dirs = set(os.listdir(build_root))\n+        valid_builds = [b.dest for b in self.env['runbot.build'].search([\n+            ('dest', 'in', list(build_dirs)),\n+            ('state', '!=', 'done')\n+        ])]\n+        for pattern in build_dirs.difference(valid_builds):\n+            _logger.info(\"Runbot Janitor Cleaning up Residue: %s\" % pattern)\n+            self.clean_up_database(pattern)\n+            self.clean_up_process(pattern)\n+            self.clean_up_filesystem(pattern)\n+","path":"runbot_janitor/models/runbot_repo.py","position":103,"original_position":103,"commit_id":"2e8f921ee48762daec1f0dfc9186d6fe43af02f3","original_commit_id":"2e8f921ee48762daec1f0dfc9186d6fe43af02f3","user":{"login":"gurneyalex","id":2032807,"avatar_url":"https://avatars.githubusercontent.com/u/2032807?v=3","gravatar_id":"","url":"https://api.github.com/users/gurneyalex","html_url":"https://github.com/gurneyalex","followers_url":"https://api.github.com/users/gurneyalex/followers","following_url":"https://api.github.com/users/gurneyalex/following{/other_user}","gists_url":"https://api.github.com/users/gurneyalex/gists{/gist_id}","starred_url":"https://api.github.com/users/gurneyalex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gurneyalex/subscriptions","organizations_url":"https://api.github.com/users/gurneyalex/orgs","repos_url":"https://api.github.com/users/gurneyalex/repos","events_url":"https://api.github.com/users/gurneyalex/events{/privacy}","received_events_url":"https://api.github.com/users/gurneyalex/received_events","type":"User","site_admin":false},"body":"I confirm this is required: on the OCA  instance I get:\r\n\r\n    2014-12-16 11:17:43,503 5000 ERROR openerp-oca-runbot openerp.addons.base.ir.ir_cron: Call of self.pool.get('runbot.repo').cron(cr, uid, *()) failed in Job 6\r\n    Traceback (most recent call last):\r\n      File \"/srv/openerp/instances/openerp-oca-runbot/parts/server/openerp/addons/base/ir/ir_cron.py\", line 138, in _callback\r\n        getattr(model, method_name)(cr, uid, *args)\r\n      File \"/srv/openerp/instances/openerp-oca-runbot/parts/server/openerp/api.py\", line 237, in wrapper\r\n        return old_api(self, *args, **kwargs)\r\n      File \"/srv/openerp/instances/openerp-oca-runbot/parts/server/openerp/api.py\", line 332, in old_api\r\n        result = method(recs, *args, **kwargs)\r\n      File \"/srv/openerp/instances/openerp-oca-runbot/parts/runbot-addons/runbot_janitor/models/runbot_repo.py\", line 79, in cron\r\n        self.clean_up()\r\n      File \"/srv/openerp/instances/openerp-oca-runbot/parts/runbot-addons/runbot_janitor/models/runbot_repo.py\", line 89, in clean_up\r\n        self.clean_up_pids()\r\n      File \"/srv/openerp/instances/openerp-oca-runbot/parts/runbot-addons/runbot_janitor/models/runbot_repo.py\", line 121, in clean_up_pids\r\n        os.kill(build.pid, signal.SIGKILL)\r\n    OSError: [Errno 1] Operation not permitted\r\n","created_at":"2014-12-16T11:20:10Z","updated_at":"2014-12-16T11:20:10Z","html_url":"https://github.com/OCA/runbot-addons/pull/17#discussion_r21891296","pull_request_url":"https://api.github.com/repos/OCA/runbot-addons/pulls/17","_links":{"self":{"href":"https://api.github.com/repos/OCA/runbot-addons/pulls/comments/21891296"},"html":{"href":"https://github.com/OCA/runbot-addons/pull/17#discussion_r21891296"},"pull_request":{"href":"https://api.github.com/repos/OCA/runbot-addons/pulls/17"}}},"pull_request":{"url":"https://api.github.com/repos/OCA/runbot-addons/pulls/17","id":26015782,"html_url":"https://github.com/OCA/runbot-addons/pull/17","diff_url":"https://github.com/OCA/runbot-addons/pull/17.diff","patch_url":"https://github.com/OCA/runbot-addons/pull/17.patch","issue_url":"https://api.github.com/repos/OCA/runbot-addons/issues/17","number":17,"state":"open","locked":false,"title":"Runbot Agressive Janitor","user":{"login":"bwrsandman","id":1013356,"avatar_url":"https://avatars.githubusercontent.com/u/1013356?v=3","gravatar_id":"","url":"https://api.github.com/users/bwrsandman","html_url":"https://github.com/bwrsandman","followers_url":"https://api.github.com/users/bwrsandman/followers","following_url":"https://api.github.com/users/bwrsandman/following{/other_user}","gists_url":"https://api.github.com/users/bwrsandman/gists{/gist_id}","starred_url":"https://api.github.com/users/bwrsandman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bwrsandman/subscriptions","organizations_url":"https://api.github.com/users/bwrsandman/orgs","repos_url":"https://api.github.com/users/bwrsandman/repos","events_url":"https://api.github.com/users/bwrsandman/events{/privacy}","received_events_url":"https://api.github.com/users/bwrsandman/received_events","type":"User","site_admin":false},"body":"This is a module whose aim is to save space and processing power\r\n\r\nIt checks the runbot build directory for old builds.\r\nIt checks by looking at running builds and comparing the with the contents of the build directory. Any extra builds are removed along with associated databases.\r\nIt will also do it's best at kill processes which are orphaned.\r\n\r\nAdditionally, it sets all builds as done when starting up: A big issue with runbot is that when restarting the server, the build objects are still marked as running when they're clearly not.\r\n\r\nCredit to @foutoucour who helped out with the implementation, especially the tests.","created_at":"2014-12-13T02:32:30Z","updated_at":"2014-12-16T11:20:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c9542b0e14d63bdaa1fdfb49988ae8afc8262520","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/OCA/runbot-addons/pulls/17/commits","review_comments_url":"https://api.github.com/repos/OCA/runbot-addons/pulls/17/comments","review_comment_url":"https://api.github.com/repos/OCA/runbot-addons/pulls/comments/{number}","comments_url":"https://api.github.com/repos/OCA/runbot-addons/issues/17/comments","statuses_url":"https://api.github.com/repos/OCA/runbot-addons/statuses/2e8f921ee48762daec1f0dfc9186d6fe43af02f3","head":{"label":"savoirfairelinux:janitor","ref":"janitor","sha":"2e8f921ee48762daec1f0dfc9186d6fe43af02f3","user":{"login":"savoirfairelinux","id":2735545,"avatar_url":"https://avatars.githubusercontent.com/u/2735545?v=3","gravatar_id":"","url":"https://api.github.com/users/savoirfairelinux","html_url":"https://github.com/savoirfairelinux","followers_url":"https://api.github.com/users/savoirfairelinux/followers","following_url":"https://api.github.com/users/savoirfairelinux/following{/other_user}","gists_url":"https://api.github.com/users/savoirfairelinux/gists{/gist_id}","starred_url":"https://api.github.com/users/savoirfairelinux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/savoirfairelinux/subscriptions","organizations_url":"https://api.github.com/users/savoirfairelinux/orgs","repos_url":"https://api.github.com/users/savoirfairelinux/repos","events_url":"https://api.github.com/users/savoirfairelinux/events{/privacy}","received_events_url":"https://api.github.com/users/savoirfairelinux/received_events","type":"Organization","site_admin":false},"repo":{"id":21168823,"name":"runbot-addons","full_name":"savoirfairelinux/runbot-addons","owner":{"login":"savoirfairelinux","id":2735545,"avatar_url":"https://avatars.githubusercontent.com/u/2735545?v=3","gravatar_id":"","url":"https://api.github.com/users/savoirfairelinux","html_url":"https://github.com/savoirfairelinux","followers_url":"https://api.github.com/users/savoirfairelinux/followers","following_url":"https://api.github.com/users/savoirfairelinux/following{/other_user}","gists_url":"https://api.github.com/users/savoirfairelinux/gists{/gist_id}","starred_url":"https://api.github.com/users/savoirfairelinux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/savoirfairelinux/subscriptions","organizations_url":"https://api.github.com/users/savoirfairelinux/orgs","repos_url":"https://api.github.com/users/savoirfairelinux/repos","events_url":"https://api.github.com/users/savoirfairelinux/events{/privacy}","received_events_url":"https://api.github.com/users/savoirfairelinux/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/savoirfairelinux/runbot-addons","description":"","fork":true,"url":"https://api.github.com/repos/savoirfairelinux/runbot-addons","forks_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/forks","keys_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/keys{/key_id}","collaborators_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/teams","hooks_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/hooks","issue_events_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/issues/events{/number}","events_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/events","assignees_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/assignees{/user}","branches_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/branches{/branch}","tags_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/tags","blobs_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/git/refs{/sha}","trees_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/git/trees{/sha}","statuses_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/statuses/{sha}","languages_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/languages","stargazers_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/stargazers","contributors_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/contributors","subscribers_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/subscribers","subscription_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/subscription","commits_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/commits{/sha}","git_commits_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/git/commits{/sha}","comments_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/comments{/number}","issue_comment_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/issues/comments/{number}","contents_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/contents/{+path}","compare_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/compare/{base}...{head}","merges_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/merges","archive_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/downloads","issues_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/issues{/number}","pulls_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/pulls{/number}","milestones_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/milestones{/number}","notifications_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/labels{/name}","releases_url":"https://api.github.com/repos/savoirfairelinux/runbot-addons/releases{/id}","created_at":"2014-06-24T14:55:52Z","updated_at":"2014-06-24T16:02:04Z","pushed_at":"2014-12-15T23:05:18Z","git_url":"git://github.com/savoirfairelinux/runbot-addons.git","ssh_url":"git@github.com:savoirfairelinux/runbot-addons.git","clone_url":"https://github.com/savoirfairelinux/runbot-addons.git","svn_url":"https://github.com/savoirfairelinux/runbot-addons","homepage":null,"size":289,"stargazers_count":0,"watchers_count":0,"language":null,"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":"8.0"}},"base":{"label":"OCA:8.0","ref":"8.0","sha":"f93549b699ebb0f6bcd0287349a24946b2a052a4","user":{"login":"OCA","id":7600578,"avatar_url":"https://avatars.githubusercontent.com/u/7600578?v=3","gravatar_id":"","url":"https://api.github.com/users/OCA","html_url":"https://github.com/OCA","followers_url":"https://api.github.com/users/OCA/followers","following_url":"https://api.github.com/users/OCA/following{/other_user}","gists_url":"https://api.github.com/users/OCA/gists{/gist_id}","starred_url":"https://api.github.com/users/OCA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OCA/subscriptions","organizations_url":"https://api.github.com/users/OCA/orgs","repos_url":"https://api.github.com/users/OCA/repos","events_url":"https://api.github.com/users/OCA/events{/privacy}","received_events_url":"https://api.github.com/users/OCA/received_events","type":"Organization","site_admin":false},"repo":{"id":21156013,"name":"runbot-addons","full_name":"OCA/runbot-addons","owner":{"login":"OCA","id":7600578,"avatar_url":"https://avatars.githubusercontent.com/u/7600578?v=3","gravatar_id":"","url":"https://api.github.com/users/OCA","html_url":"https://github.com/OCA","followers_url":"https://api.github.com/users/OCA/followers","following_url":"https://api.github.com/users/OCA/following{/other_user}","gists_url":"https://api.github.com/users/OCA/gists{/gist_id}","starred_url":"https://api.github.com/users/OCA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OCA/subscriptions","organizations_url":"https://api.github.com/users/OCA/orgs","repos_url":"https://api.github.com/users/OCA/repos","events_url":"https://api.github.com/users/OCA/events{/privacy}","received_events_url":"https://api.github.com/users/OCA/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/OCA/runbot-addons","description":"Runbot Custom Features to be used by community.","fork":false,"url":"https://api.github.com/repos/OCA/runbot-addons","forks_url":"https://api.github.com/repos/OCA/runbot-addons/forks","keys_url":"https://api.github.com/repos/OCA/runbot-addons/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OCA/runbot-addons/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OCA/runbot-addons/teams","hooks_url":"https://api.github.com/repos/OCA/runbot-addons/hooks","issue_events_url":"https://api.github.com/repos/OCA/runbot-addons/issues/events{/number}","events_url":"https://api.github.com/repos/OCA/runbot-addons/events","assignees_url":"https://api.github.com/repos/OCA/runbot-addons/assignees{/user}","branches_url":"https://api.github.com/repos/OCA/runbot-addons/branches{/branch}","tags_url":"https://api.github.com/repos/OCA/runbot-addons/tags","blobs_url":"https://api.github.com/repos/OCA/runbot-addons/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OCA/runbot-addons/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OCA/runbot-addons/git/refs{/sha}","trees_url":"https://api.github.com/repos/OCA/runbot-addons/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OCA/runbot-addons/statuses/{sha}","languages_url":"https://api.github.com/repos/OCA/runbot-addons/languages","stargazers_url":"https://api.github.com/repos/OCA/runbot-addons/stargazers","contributors_url":"https://api.github.com/repos/OCA/runbot-addons/contributors","subscribers_url":"https://api.github.com/repos/OCA/runbot-addons/subscribers","subscription_url":"https://api.github.com/repos/OCA/runbot-addons/subscription","commits_url":"https://api.github.com/repos/OCA/runbot-addons/commits{/sha}","git_commits_url":"https://api.github.com/repos/OCA/runbot-addons/git/commits{/sha}","comments_url":"https://api.github.com/repos/OCA/runbot-addons/comments{/number}","issue_comment_url":"https://api.github.com/repos/OCA/runbot-addons/issues/comments/{number}","contents_url":"https://api.github.com/repos/OCA/runbot-addons/contents/{+path}","compare_url":"https://api.github.com/repos/OCA/runbot-addons/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OCA/runbot-addons/merges","archive_url":"https://api.github.com/repos/OCA/runbot-addons/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OCA/runbot-addons/downloads","issues_url":"https://api.github.com/repos/OCA/runbot-addons/issues{/number}","pulls_url":"https://api.github.com/repos/OCA/runbot-addons/pulls{/number}","milestones_url":"https://api.github.com/repos/OCA/runbot-addons/milestones{/number}","notifications_url":"https://api.github.com/repos/OCA/runbot-addons/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OCA/runbot-addons/labels{/name}","releases_url":"https://api.github.com/repos/OCA/runbot-addons/releases{/id}","created_at":"2014-06-24T07:29:14Z","updated_at":"2014-12-16T10:06:30Z","pushed_at":"2014-12-16T10:06:30Z","git_url":"git://github.com/OCA/runbot-addons.git","ssh_url":"git@github.com:OCA/runbot-addons.git","clone_url":"https://github.com/OCA/runbot-addons.git","svn_url":"https://github.com/OCA/runbot-addons","homepage":"","size":432,"stargazers_count":2,"watchers_count":2,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":7,"forks":7,"open_issues":7,"watchers":2,"default_branch":"8.0"}},"_links":{"self":{"href":"https://api.github.com/repos/OCA/runbot-addons/pulls/17"},"html":{"href":"https://github.com/OCA/runbot-addons/pull/17"},"issue":{"href":"https://api.github.com/repos/OCA/runbot-addons/issues/17"},"comments":{"href":"https://api.github.com/repos/OCA/runbot-addons/issues/17/comments"},"review_comments":{"href":"https://api.github.com/repos/OCA/runbot-addons/pulls/17/comments"},"review_comment":{"href":"https://api.github.com/repos/OCA/runbot-addons/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/OCA/runbot-addons/pulls/17/commits"},"statuses":{"href":"https://api.github.com/repos/OCA/runbot-addons/statuses/2e8f921ee48762daec1f0dfc9186d6fe43af02f3"}}}}