summaryrefslogtreecommitdiff
path: root/lorrycontroller
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-10-02 09:56:34 +0100
committerDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-10-02 09:56:34 +0100
commit1d4eba57f93d0ed561bd05053079f3256ed645bd (patch)
tree465b7686480ab409510a6e8b237f7a4aeec016b4 /lorrycontroller
parent6a51c368a9cf0a39bd5c1f5edd56eeb9c3d73de2 (diff)
downloadlorry-controller-1d4eba57f93d0ed561bd05053079f3256ed645bd.tar.gz
Support due-time and decide what to run and when
Diffstat (limited to 'lorrycontroller')
-rw-r--r--lorrycontroller/confparser.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/lorrycontroller/confparser.py b/lorrycontroller/confparser.py
index 4a3ec8f..d23cf4c 100644
--- a/lorrycontroller/confparser.py
+++ b/lorrycontroller/confparser.py
@@ -6,6 +6,7 @@ import logging
import re
import glob
import os
+import time
default_values = [
( u'serial', 0 ),
@@ -30,6 +31,8 @@ class LorryControllerConfig(object):
def __init__(self, settings, confpath):
self.settings = settings
self.lorries = {}
+ self.configs = {}
+ self.duetimes = {}
confpath = os.path.join(settings['work-area'], confpath)
logging.debug("Parsing configuration: %s" % confpath)
with open(confpath, "r") as fh:
@@ -111,6 +114,7 @@ class LorryControllerConfig(object):
len(my_lorries))
logging.debug("Loading lorries into memory, please wait...")
+ my_lorry_names = set()
for lorry in my_lorries:
try:
with open(lorry, "r") as fh:
@@ -120,11 +124,23 @@ class LorryControllerConfig(object):
if self.lorries.get(fullname, None) is not None:
self._give_up("Lorry repeated: %s" % fullname)
content['serial'] = entry['serial']
+ my_lorry_names.add(fullname)
self.lorries[fullname] = content
+ self.configs[fullname] = entry
except Exception, e:
logging.debug("Unable to parse %s, because of %s. Moving on" %
(lorry, e))
+ # Now calculate the 'next due' time for every lorry we just parsed
+ starttime = time.time() - 1
+ endtime = starttime + entry['interval-parsed']
+ step = 0
+ if entry['stagger']:
+ step = (endtime - starttime) / len(my_lorry_names)
+ for lorry_name in my_lorry_names:
+ self.duetimes[lorry_name] = starttime
+ starttime += step
+
logging.debug("Now loaded %d lorries" % len(self.lorries.keys()))
def _give_up(self, *args, **kwargs):