Commit 23bef989 authored by Romain Courteaud's avatar Romain Courteaud

Reread configuration file between every loop

parent b22b441b
...@@ -33,6 +33,7 @@ def rfc822(date): ...@@ -33,6 +33,7 @@ def rfc822(date):
class WebBot: class WebBot:
def __init__(self, **kw): def __init__(self, **kw):
self.config_kw = kw
self.config = createConfiguration(**kw) self.config = createConfiguration(**kw)
def closeDB(self): def closeDB(self):
...@@ -61,6 +62,10 @@ class WebBot: ...@@ -61,6 +62,10 @@ class WebBot:
def iterateLoop(self): def iterateLoop(self):
status_id = logStatus(self._db, "loop") status_id = logStatus(self._db, "loop")
if self.config["RELOAD"] == "True":
self.config = createConfiguration(**self.config_kw)
timeout = int(self.config["TIMEOUT"]) timeout = int(self.config["TIMEOUT"])
# logPlatform(self._db, __version__, status_id) # logPlatform(self._db, __version__, status_id)
......
...@@ -22,6 +22,12 @@ from urlchecker_bot import create_bot ...@@ -22,6 +22,12 @@ from urlchecker_bot import create_bot
@click.option( @click.option(
"--configuration", "-f", help="The path of the configuration file." "--configuration", "-f", help="The path of the configuration file."
) )
@click.option(
"--reload/--no-reload",
default=False,
help="Reload the configuration file between each crawl.",
show_default=True,
)
@click.option( @click.option(
"--output", "--output",
"-o", "-o",
...@@ -31,7 +37,15 @@ from urlchecker_bot import create_bot ...@@ -31,7 +37,15 @@ from urlchecker_bot import create_bot
show_default=True, show_default=True,
) )
def runUrlChecker( def runUrlChecker(
run, sqlite, nameserver, url, domain, timeout, configuration, output run,
sqlite,
nameserver,
url,
domain,
timeout,
configuration,
reload,
output,
): ):
# click.echo("Running url checker bot") # click.echo("Running url checker bot")
...@@ -47,6 +61,8 @@ def runUrlChecker( ...@@ -47,6 +61,8 @@ def runUrlChecker(
mapping["SQLITE"] = sqlite mapping["SQLITE"] = sqlite
if nameserver: if nameserver:
mapping["NAMESERVER"] = nameserver mapping["NAMESERVER"] = nameserver
if reload:
mapping["RELOAD"] = str(reload)
mapping["FORMAT"] = output mapping["FORMAT"] = output
bot = create_bot(cfgfile=configuration, mapping=mapping) bot = create_bot(cfgfile=configuration, mapping=mapping)
return bot.run(run) return bot.run(run)
......
...@@ -32,6 +32,8 @@ def createConfiguration( ...@@ -32,6 +32,8 @@ def createConfiguration(
config[CONFIG_SECTION]["FORMAT"] = "json" config[CONFIG_SECTION]["FORMAT"] = "json"
if "TIMEOUT" not in config[CONFIG_SECTION]: if "TIMEOUT" not in config[CONFIG_SECTION]:
config[CONFIG_SECTION]["TIMEOUT"] = "1" config[CONFIG_SECTION]["TIMEOUT"] = "1"
if "RELOAD" not in config[CONFIG_SECTION]:
config[CONFIG_SECTION]["RELOAD"] = str(False)
if config[CONFIG_SECTION]["SQLITE"] == ":memory:": if config[CONFIG_SECTION]["SQLITE"] == ":memory:":
# Do not loop when using temporary DB # Do not loop when using temporary DB
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment