diff options
author | Rob Austein <sra@hactrn.net> | 2009-07-14 19:20:48 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2009-07-14 19:20:48 +0000 |
commit | 678bcfd8613bfe3b6cbd7416c053fe004f4d3b3a (patch) | |
tree | a91293786a917cfd5fa79a5c0c32a84ed6e8550d /rpkid | |
parent | 24baff4d45adb16b3f33b8a2c200cdaf38778af5 (diff) |
First cut at internal clock for cron tasks. Doesn't work right yet,
and timing parameters will need adjusting in any case.
svn path=/rpkid/rpki/rpki_engine.py; revision=2617
Diffstat (limited to 'rpkid')
-rw-r--r-- | rpkid/rpki/rpki_engine.py | 48 | ||||
-rwxr-xr-x | rpkid/rpkid.py | 2 | ||||
-rw-r--r-- | rpkid/testbed.py | 2 |
3 files changed, 45 insertions, 7 deletions
diff --git a/rpkid/rpki/rpki_engine.py b/rpkid/rpki/rpki_engine.py index a01bc956..78c29966 100644 --- a/rpkid/rpki/rpki_engine.py +++ b/rpkid/rpki/rpki_engine.py @@ -32,7 +32,7 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ -import lxml.etree, re +import lxml.etree, re, random import rpki.resource_set, rpki.up_down, rpki.left_right, rpki.x509, rpki.sql import rpki.https, rpki.config, rpki.exceptions, rpki.relaxng, rpki.log, rpki.async @@ -54,10 +54,29 @@ class rpkid_context(object): self.irdb_url = cfg.get("irdb-url") self.https_server_host = cfg.get("server-host", "") - self.https_server_port = int(cfg.get("server-port", "4433")) + self.https_server_port = cfg.getint("server-port", 4433) self.publication_kludge_base = cfg.get("publication-kludge-base", "publication/") + self.use_internal_clock = cfg.getboolean("use-internal-clock", True) + + self.initial_delay = random.randint(cfg.getint("initial-delay-min", 10), + cfg.getint("initial-delay-max", 120)) + + self.cron_period = cfg.getint("cron-period", 120) # Should be much longer in production + + def start_clock(self): + """ + Start rpkid's internal clock. + """ + + if self.use_internal_clock: + when = rpki.sundial.now() + rpki.sundial.timedelta(seconds = self.initial_delay) + rpki.log.debug("Scheduling initial cron pass at %s" % when) + rpki.async.timer(handler = self.cron).set(when) + else: + rpki.log.debug("Not using internal clock, start_clock() call ignored") + def irdb_query(self, q_pdu, callback, errback): """ Perform an IRDB callback query. @@ -176,11 +195,9 @@ class rpkid_context(object): rpki.log.traceback() cb(400, "Could not process PDU: %s" % data) - def cronjob_handler(self, query, path, cb): + def cron(self, cb = None): """ - Periodic tasks. This is somewhat obsolete now that we have - internal timers, but the test framework still uses this, and I - haven't yet refactored this code to use the new timers. + Periodic tasks. """ rpki.log.trace() @@ -208,10 +225,27 @@ class rpkid_context(object): def done(): self.sql.sweep() - cb(200, "OK") + if cb is not None: + cb() + else: + when = rpki.sundial.now() + rpki.sundial.timedelta(seconds = self.cron_period) + rpki.log.debug("Scheduling next cron run at %s" % when) + rpki.async.timer(handler = self.cron).set(when) rpki.async.iterator(rpki.left_right.self_elt.sql_fetch_all(self), loop, done) + def cronjob_handler(self, query, path, cb): + """ + External trigger for periodic tasks. This is somewhat obsolete + now that we have internal timers, but the test framework still + uses it. + """ + + if self.use_internal_clock: + cb(500, "Running on internal clock") + else: + self.cron(lambda: cb(200, "OK")) + ## @var https_ta_cache # HTTPS trust anchor cache, to avoid regenerating it for every TLS connection. https_ta_cache = None diff --git a/rpkid/rpkid.py b/rpkid/rpkid.py index 04325c9b..34ef5d80 100755 --- a/rpkid/rpkid.py +++ b/rpkid/rpkid.py @@ -76,6 +76,8 @@ def main(): gctx = rpki.rpki_engine.rpkid_context(cfg) + gctx.start_clock() + rpki.https.server(host = gctx.https_server_host, port = gctx.https_server_port, server_key = gctx.rpkid_key, diff --git a/rpkid/testbed.py b/rpkid/testbed.py index c150b821..451ec88a 100644 --- a/rpkid/testbed.py +++ b/rpkid/testbed.py @@ -1342,6 +1342,8 @@ irdb-url = https://localhost:%(irdb_port)d/ server-host = localhost server-port = %(rpki_port)d + +use-internal-clock = false ''' rootd_fmt_1 = '''\ |