Skip to content

Commit 58cda7b

Browse files
committed
[IMP] runbot: allow to send status in a service
Currently the leader and status service are synchronous, meaning that if either fetching a repo or sending a status is slow, the other is impacted. In some cases, a fetch may take a verry long time pausing the status updates. In other cases, github is slow to answer making the satus updates slow taking some times multiple minutes to be sent. Moreover, during the send of a status batch, new status could already exists making the sent status outdated. To solve these issues, we introduce a status service that will be responsible for sending the status updates. This is optional and by default the leader will still send the status updates. Additionnally, we only send status on build older than 2 minutes to avoid sending status that could be quickly outdated (style, cla, instantly failling builds).
1 parent 4489288 commit 58cda7b

6 files changed

Lines changed: 22 additions & 4 deletions

File tree

runbot/models/commit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class CommitStatus(models.Model):
262262
to_process = fields.Boolean('Status was not processed yet', index=True)
263263

264264
def _send_to_process(self):
265-
commits_status = self.search([('to_process', '=', True)], order='create_date DESC, id DESC')
265+
commits_status = self.search([('to_process', '=', True), ('build_id.create_date', '<', datetime.datetime.now() - datetime.timedelta(minutes=2))], order='create_date DESC, id DESC')
266266
if commits_status:
267267
_logger.info('Sending %s commit status', len(commits_status))
268268
commits_status._send()

runbot/models/host.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class Host(models.Model):
4949
is_leader = fields.Boolean('Is leader', help='This host is the leader of the cluster', default=False)
5050
is_builder = fields.Boolean('Is builder', help='This host is a builder of the cluster', default=True)
5151
is_registry = fields.Boolean('Is docker registry', help='This host is a docker regisrty', default=False)
52+
send_status = fields.Boolean('Send status', help='If leader, this host will send status updates, disable to use the status service', default=True)
5253

5354
use_remote_docker_registry = fields.Boolean('Use remote Docker Registry', default=False, help="Use docker registry for pulling images")
5455
docker_registry_url = fields.Char('Registry Url', help="Override global registry URL for this host.")

runbot/models/runbot.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,6 @@ def _fetch_loop_turn(self, host, pull_info_failures, default_sleep=1):
271271
self._commit()
272272
self._commit()
273273

274-
self.env['runbot.commit.status']._send_to_process()
275-
self._commit()
276274

277275
# cleanup old pull_info_failures
278276
for pr_number, t in pull_info_failures.copy().items():

runbot/views/host_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<field name="active"/>
1414
<field name="use_remote_docker_registry"/>
1515
<field name="is_leader"/>
16+
<field name="send_status" invisible="not is_leader"/>
1617
<field name="is_builder"/>
1718
<field name="is_registry"/>
1819
<field name="docker_registry_url"/>
@@ -58,7 +59,6 @@
5859
<field name="use_remote_docker_registry" widget="boolean_toggle"/>
5960
<field name="nb_worker"/>
6061
<field name="nb_run_slot"/>
61-
6262
<field name="is_leader"/>
6363
<field name="is_builder"/>
6464
<field name="is_registry"/>

runbot_builder/leader.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ def loop_turn(self):
2727
self.env.cr.commit()
2828
self.git_gc()
2929
self.env.cr.commit()
30+
31+
if self.host.send_status:
32+
self.env['runbot.commit.status']._send_to_process()
33+
self.env.cr.commit()
34+
3035
return self.env['runbot.runbot']._fetch_loop_turn(self.host, self.pull_info_failures)
3136

3237

runbot_builder/status.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/python3
2+
from tools import RunbotClient, run
3+
4+
5+
class StatusClient(RunbotClient):
6+
7+
def loop_turn(self):
8+
self.env['runbot.commit.status']._send_to_process()
9+
self.env.cr.commit()
10+
return 5
11+
12+
13+
if __name__ == '__main__':
14+
run(StatusClient)

0 commit comments

Comments
 (0)