Commit 3d59c18c authored by Jeremy Pallats's avatar Jeremy Pallats 💬
Browse files

FIX #117: Bug on cycle update, config returned to ...

- Always check that what is read is good before replacing live conf.
- Remove the shortcut of top inside cycle. There is a race condition
  between them as cycle modifies the db top is reading. Users should top
  before cycle manually.
parent 34f51164
Loading
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -317,7 +317,6 @@ class Admin(Action):

    async def top(self, limit=5):
        """ Schedule all sheets for update. """
        # TODO: Fetch cycle from Global.
        cycle = cog.util.CONF.scanners.hudson_cattle.page
        prefix = "__Top Merits for {}__\n\n".format(cycle)
        try:
@@ -369,7 +368,6 @@ class Admin(Action):
            InternalException - No parseable numeric component found in tab.
            RemoteError - The sheet/tab combination could not be resolved. Tab needs creating.
        """
        await self.top(5)
        # Zero trackers for new ocr data
        cogdb.query.post_cycle_db_cleanup(self.session)
        self.bot.deny_commands = True
+14 −6
Original line number Diff line number Diff line
@@ -131,10 +131,13 @@ class Config():

            The contents of CONFIG_DEFAULTS dictionary updated with the contents of the file load.
        """
        self.conf = copy.deepcopy(CONFIG_DEFAULTS)
        conf = copy.deepcopy(CONFIG_DEFAULTS)
        with open(self.fname) as fin:
            loaded = yaml.load(fin, Loader=Loader)
        self.conf.update(loaded)

            if loaded:
                conf.update(loaded)
                self.conf = conf

    def write(self):
        """
@@ -161,10 +164,15 @@ class Config():
        """
        Async version of read.
        """
        self.conf = copy.deepcopy(CONFIG_DEFAULTS)
        async with aiofiles.open(self.fname) as fin:
            loaded = yaml.load(await fin.read(), Loader=Loader)
        self.conf.update(loaded)
        conf = copy.deepcopy(CONFIG_DEFAULTS)
        async with aiofiles.open(self.fname, 'r', encoding='utf-8') as fin:
            text = await fin.read()
            print(text)
            loaded = yaml.load(text, Loader=Loader)

            if loaded:
                conf.update(loaded)
                self.conf = conf

    async def awrite(self):
        """