adjust touch target on mobile Feature page
[people/shoehn/ipfire.org.git] / manager.py
CommitLineData
940227cb
MT
1#!/usr/bin/python
2
3import logging
4import time
5import tornado.ioloop
6
7import webapp.backend as backend
8
9class Daemon(object):
10 def __init__(self):
11 self._managers = []
12
13 self.ioloop.set_blocking_log_threshold(900)
14
9068dba1
MT
15 self.backend = backend.Backend("webapp.conf")
16
940227cb
MT
17 @property
18 def ioloop(self):
19 return tornado.ioloop.IOLoop.instance()
20
21 def add(self, manager_cls):
22 manager = manager_cls(self)
23 self._managers.append(manager)
24
25 def run(self):
26 """
27 Main loop.
28 """
29 for manager in self._managers:
30 manager.pc.start()
31
32 self.ioloop.start()
33
34 def shutdown(self):
35 self.ioloop.stop()
36
37
38class Manager(object):
39 def __init__(self, daemon):
40 self.daemon = daemon
41
42 self.pc = tornado.ioloop.PeriodicCallback(self, self.timeout * 1000)
43
44 logging.info("%s was initialized." % self.__class__.__name__)
45
46 self()
47
48 def __call__(self):
49 logging.info("%s main method was called." % self.__class__.__name__)
50
51 self.do()
52
53 # Update callback_time.
54 self.pc.callback_time = self.timeout * 1000
55 logging.debug("Next call will be in %.2f seconds." % \
56 (self.pc.callback_time / 1000))
57
9068dba1
MT
58 @property
59 def backend(self):
60 return self.daemon.backend
61
62 @property
63 def settings(self):
64 return self.backend.settings
65
940227cb
MT
66 @property
67 def timeout(self):
68 """
69 Return a new callback timeout in seconds.
70 """
71 raise NotImplementedError
72
73 def do(self):
74 raise NotImplementedError
75
76
77
78class MirrorManager(Manager):
79 @property
80 def mirrors(self):
9068dba1 81 return self.backend.mirrors
940227cb
MT
82
83 @property
84 def timeout(self):
9068dba1 85 return self.backend.settings.get_int("mirror_check_interval", 3600)
940227cb
MT
86
87 def do(self):
88 # Check status of all mirror servers.
89 self.mirrors.check_all()
90
91
3c4f2edc
MT
92class ReleaseFilesManager(Manager):
93 @property
94 def releases(self):
9068dba1 95 return self.backend.releases
3c4f2edc
MT
96
97 @property
98 def timeout(self):
9068dba1 99 return self.settings.get_int("releasefiles_check_interval", 3600)
3c4f2edc
MT
100
101 def do(self):
d0eee7f8 102 for release in self.releases._get_all():
3c4f2edc
MT
103 release.scan_files()
104
105
940227cb
MT
106if __name__ == "__main__":
107 d = Daemon()
108 d.add(MirrorManager)
3c4f2edc 109 d.add(ReleaseFilesManager)
940227cb
MT
110
111 d.run()