Skip to content

Commit e02e7e5

Browse files
author
Odoo Online
committed
[FIX] runbot: repo hook
1 parent c1fad49 commit e02e7e5

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

runbot/runbot.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
_re_warning = r'^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d,\d{3} \d+ WARNING '
4444
_re_job = re.compile('job_\d')
4545

46+
# monkey patch cron system to reduce starvation and improve throughput with many workers
47+
openerp.service.server.SLEEP_INTERVAL = 4
4648

4749
#----------------------------------------------------------
4850
# RunBot helpers
@@ -179,11 +181,10 @@ def _get_base(self, cr, uid, ids, field_name, arg, context=None):
179181
'path': fields.function(_get_path, type='char', string='Directory', readonly=1),
180182
'base': fields.function(_get_base, type='char', string='Base URL', readonly=1),
181183
'nginx': fields.boolean('Nginx'),
182-
'auto': fields.boolean('Auto'),
183-
'mode': fields.selection([('disabled', 'Dont check for new build'),
184-
('poll', 'Poll git repository'),
185-
('hook', 'Wait for webhook on /runbot/hook/<id> i.e. github push event')],
186-
string="Mode"),
184+
'mode': fields.selection([('disabled', 'Disabled'),
185+
('poll', 'Poll'),
186+
('hook', 'Hook')],
187+
string="Mode", required=True, help="hook: Wait for webhook on /runbot/hook/<id> i.e. github push event"),
187188
'hook_time': fields.datetime('Last hook time'),
188189
'duplicate_id': fields.many2one('runbot.repo', 'Duplicate repo', help='Repository for finding duplicate builds'),
189190
'modules': fields.char("Modules to install", help="Comma-separated list of modules to install and test."),
@@ -273,6 +274,8 @@ def update_git(self, cr, uid, repo, context=None):
273274
# check for mode == hook
274275
fetch_time = os.path.getmtime(os.path.join(repo.path, 'FETCH_HEAD'))
275276
if repo.mode == 'hook' and repo.hook_time and dt2time(repo.hook_time) < fetch_time:
277+
t0 = time.time()
278+
_logger.debug('repo %s skip hook fetch fetch_time: %ss ago hook_time: %ss ago', repo.name, int(t0 - fetch_time), int(t0 - dt2time(repo.hook_time)))
276279
return
277280

278281
repo.git(['gc', '--auto', '--prune=all'])
@@ -1227,10 +1230,11 @@ def branch_info(branch):
12271230

12281231
return request.render("runbot.repo", context)
12291232

1230-
@http.route(['/runbot', '/runbot/hook/<repo_id:int>'], type='http', auth="public", website=True)
1231-
def repo(self, repo_id=None, **post):
1232-
repo = request.registry['runbot.repo'].browse(cr, SUPERUSER_ID, [repo_id])
1233-
repo.hook_time = datetime.now().strftime(DEFAULT_SERVER_DATETIME_FORMAT)
1233+
@http.route(['/runbot/hook/<int:repo_id>'], type='http', auth="public", website=True)
1234+
def hook(self, repo_id=None, **post):
1235+
# TODO if repo_id == None parse the json['repository']['ssh_url'] and find the right repo
1236+
repo = request.registry['runbot.repo'].browse(request.cr, SUPERUSER_ID, [repo_id])
1237+
repo.hook_time = datetime.datetime.now().strftime(openerp.tools.DEFAULT_SERVER_DATETIME_FORMAT)
12341238
return ""
12351239

12361240
@http.route(['/runbot/dashboard'], type='http', auth="public", website=True)

runbot/runbot.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<field name="arch" type="xml">
3838
<tree string="repos">
3939
<field name="name"/>
40-
<field name="auto"/>
40+
<field name="mode"/>
4141
</tree>
4242
</field>
4343
</record>

0 commit comments

Comments
 (0)