Skip to content

Commit

Permalink
Leave more time between runs of big_brother
Browse files Browse the repository at this point in the history
  • Loading branch information
waveform80 committed Jun 10, 2019
1 parent 803db28 commit 10b10e4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
12 changes: 6 additions & 6 deletions piwheels/master/big_brother.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self, config):
'downloads_last_month': 0,
'downloads_all': 0,
}
self.timestamp = datetime.now(tz=UTC) - timedelta(seconds=40)
self.last_run = datetime.now(tz=UTC) - timedelta(seconds=40)
stats_queue = self.socket(
transport.PULL, protocol=protocols.big_brother)
stats_queue.hwm = 10
Expand Down Expand Up @@ -104,13 +104,12 @@ def handle_stats(self, queue):
self.stats['builds_pending'] = sum(data.values())
elif msg == 'HOME':
# Forced rebuild from Mr. Chase
self.timestamp = datetime.now(tz=UTC) - timedelta(seconds=40)
self.last_run = datetime.now(tz=UTC) - timedelta(seconds=40)

def loop(self):
# The big brother task is not reactive; it just pumps out stats
# every 30 seconds (at most)
if datetime.now(tz=UTC) - self.timestamp > timedelta(seconds=30):
self.timestamp = datetime.now(tz=UTC)
# Leave 30 seconds between each run of the stats and (expensive) search
# index queries
if datetime.now(tz=UTC) - self.last_run > timedelta(seconds=30):
rec = self.db.get_statistics()
# Rename a couple of columns
rec['builds_last_hour'] = rec.pop('builds_count_last_hour')
Expand All @@ -119,3 +118,4 @@ def loop(self):
self.web_queue.send_msg('HOME', self.stats)
self.status_queue.send_msg('STATS', self.stats)
self.web_queue.send_msg('SEARCH', self.db.get_search_index())
self.last_run = datetime.now(tz=UTC)
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ def handle_queue():
break
elif msg == 'SEND':
queue.append(MockMessage('send', *data))
print(queue)
control.send_msg('OK')
elif msg == 'RECV':
queue.append(MockMessage('recv', *data))
Expand Down
10 changes: 5 additions & 5 deletions tests/master/test_big_brother.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def task(request, master_config):
def test_gen_skip(master_status_queue, web_queue, task):
with mock.patch('piwheels.master.big_brother.datetime') as dt:
dt.now.return_value = datetime(2018, 1, 1, 12, 30, 0, tzinfo=UTC)
task.timestamp = datetime(2018, 1, 1, 12, 30, 0, tzinfo=UTC)
task.last_run = datetime(2018, 1, 1, 12, 30, 0, tzinfo=UTC)
task.loop() # crank the handle once
with pytest.raises(transport.Error):
master_status_queue.recv_msg(flags=transport.NOBLOCK)
Expand All @@ -135,7 +135,7 @@ def test_gen_stats(db_queue, master_status_queue, web_queue, task,
stats_result, stats_dict):
with mock.patch('piwheels.master.big_brother.datetime') as dt:
dt.now.return_value = datetime(2018, 1, 1, 12, 30, 40, tzinfo=UTC)
task.timestamp = datetime(2018, 1, 1, 12, 30, 0, tzinfo=UTC)
task.last_run = datetime(2018, 1, 1, 12, 30, 0, tzinfo=UTC)
db_queue.expect('GETSTATS')
db_queue.send('OK', stats_result)
db_queue.expect('GETSEARCH')
Expand All @@ -151,7 +151,7 @@ def test_gen_disk_stats(db_queue, master_status_queue, web_queue, task,
stats_queue, stats_result, stats_dict, stats_disk):
with mock.patch('piwheels.master.big_brother.datetime') as dt:
dt.now.return_value = datetime(2018, 1, 1, 12, 30, 40, tzinfo=UTC)
task.timestamp = datetime(2018, 1, 1, 12, 30, 0, tzinfo=UTC)
task.last_run = datetime(2018, 1, 1, 12, 30, 0, tzinfo=UTC)
stats_queue.send_msg('STATFS', stats_disk)
while task.stats['disk_free'] == 0:
task.poll()
Expand All @@ -173,7 +173,7 @@ def test_gen_queue_stats(db_queue, master_status_queue, web_queue, task,
stats_queue, stats_result, stats_dict):
with mock.patch('piwheels.master.big_brother.datetime') as dt:
dt.now.return_value = datetime(2018, 1, 1, 12, 30, 40, tzinfo=UTC)
task.timestamp = datetime(2018, 1, 1, 12, 30, 0, tzinfo=UTC)
task.last_run = datetime(2018, 1, 1, 12, 30, 0, tzinfo=UTC)
stats_queue.send_msg('STATBQ', {'cp34m': 1, 'cp35m': 0})
while task.stats['builds_pending'] == 0:
task.poll()
Expand All @@ -194,7 +194,7 @@ def test_bad_stats(db_queue, master_status_queue, web_queue, task,
task.logger = mock.Mock()
with mock.patch('piwheels.master.big_brother.datetime') as dt:
dt.now.return_value = datetime(2018, 1, 1, 12, 30, 40, tzinfo=UTC)
task.timestamp = datetime(2018, 1, 1, 12, 30, 0, tzinfo=UTC)
task.last_run = datetime(2018, 1, 1, 12, 30, 0, tzinfo=UTC)
stats_queue.send(b'FOO')
task.poll()
assert task.logger.error.call_args == mock.call(
Expand Down

0 comments on commit 10b10e4

Please sign in to comment.