blob: edc64ece60f4ef13e4352f9d0df77d5758762599 [file] [log] [blame]
Chris Masone2d61ca22012-04-02 16:52:46 -07001# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import ConfigParser, logging, time
6
Chris Masone92874d32012-04-03 10:13:04 -07007import deduping_scheduler, timed_event, board_enumerator
Chris Masone2d61ca22012-04-02 16:52:46 -07008
9
10class Driver(object):
11 """Implements the main loop of the suite_scheduler.
12
13 @var _LOOP_INTERVAL: time to wait between loop iterations.
14
15 @var _scheduler: a DedupingScheduler, used to schedule jobs with the AFE.
16 @var _enumerator: a PlatformEnumerator, used to list plaforms known to
17 the AFE
18 @var _events: list of BaseEvents to be handled each time through main loop.
19 """
20
21 _LOOP_INTERVAL = 5
22
23
24 def __init__(self, afe, config):
25 """Constructor
26
27 @param afe: an instance of AFE as defined in server/frontend.py.
28 @param config: an instance of ForgivingConfigParser.
29 """
30 self._scheduler = deduping_scheduler.DedupingScheduler(afe)
Chris Masone92874d32012-04-03 10:13:04 -070031 self._enumerator = board_enumerator.PlatformEnumerator(afe)
Chris Masone2d61ca22012-04-02 16:52:46 -070032
33 # TODO(cmasone): populate this from |config|.
34 tasks = []
35
36 self._events = [timed_event.Nightly.CreateFromConfig(config, tasks),
37 timed_event.Weekly.CreateFromConfig(config, tasks)]
38
39
40 def RunForever(self):
41 """Main loop of the scheduler. Runs til the process is killed."""
42 while True:
43 self.HandleEventsOnce()
44 time.sleep(self._LOOP_INTERVAL)
45
46
47 def HandleEventsOnce(self):
48 """One turn through the loop. Separated out for unit testing."""
Chris Masone92874d32012-04-03 10:13:04 -070049 # TODO(cmasone): Make Handle() deal with boards.
50 boards = self._enumerator.Enumerate()
Chris Masone2d61ca22012-04-02 16:52:46 -070051
52 for e in self._events:
53 if e.ShouldHandle():
54 e.Handle(self._scheduler)