Commit 65e633dc authored by Jeremy Pallats's avatar Jeremy Pallats 💬
Browse files

FIX #112: Error On Admin Cycle

- Cause was an error in Config.update/aupdate, only happened at top
  level assignment.
- Reduce ocr monitor delay to 10 minutes.
- Catch case where cycle is called but worksheets do not exist, print
  useful message to user.
parent 164443ec
Loading
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ import aiofiles
import decorator
import discord
import googleapiclient.errors
import gspread
import sqlalchemy.exc
import textdistance

@@ -379,7 +380,13 @@ class Admin(Action):
            for name in ['hudson_cattle', 'hudson_undermine']:
                new_page = cog.util.number_increment(scanner_configs[name]['page'])
                scanner_configs[name]['page'] = new_page

                try:
                    await SCANNERS[name].asheet.change_worksheet(new_page)
                except gspread.exceptions.WorksheetNotFound as exc:
                    msg = f"Missing **{new_page}** worksheet on {name}. Please fix and rerun cycle. No change made."
                    raise cog.exc.InvalidCommandArgs(msg) from exc

                self.bot.sched.schedule(name, delay=1)
                lines += [[await SCANNERS[name].asheet.title(), new_page]]

@@ -2130,7 +2137,7 @@ async def monitor_carrier_events(client, *, next_summary, last_timestamp=None, d
    )


async def monitor_ocr_sheet(client, *, delay=1800, repeat=True):  # pragma: no cover
async def monitor_ocr_sheet(client, *, delay=300, repeat=True):  # pragma: no cover
    """
    Simple async task that just checks for changes to the OCR sheet.
    This task will schedule itself infinitely on a delay.
+4 −4
Original line number Diff line number Diff line
@@ -116,9 +116,9 @@ class Config():
        Kwargs:
            value: The new value to set for this key.
        """
        temp = None
        temp = self.conf
        for key in keys[:-1]:
            temp = self.conf[key]
            temp = temp[key]

        temp[keys[-1]] = value
        self.write()
@@ -149,9 +149,9 @@ class Config():
        """
        Async version of update.
        """
        temp = None
        temp = self.conf
        for key in keys[:-1]:
            temp = self.conf[key]
            temp = temp[key]

        temp[keys[-1]] = value
        await self.awrite()
+20 −0
Original line number Diff line number Diff line
@@ -68,6 +68,15 @@ def test_config_update(f_config):
        assert "zmq: 9" in fin.read()


def test_config_update_top_val(f_config):
    assert f_config.zzz is None
    f_config.update('zzz', value=9)

    assert f_config.zzz == 9
    with open(f_config.fname) as fin:
        assert "zzz: 9" in fin.read()


@pytest.mark.asyncio
async def test_config_aread(f_config):
    assert f_config.constants.ttl == cog.config.CONFIG_DEFAULTS['constants']['ttl']
@@ -94,3 +103,14 @@ async def test_config_aupdate(f_config):
    async with aiofiles.open(f_config.fname) as fin:
        text = await fin.read()
        assert "zmq: 9" in text


@pytest.mark.asyncio
async def test_config_aupdate_top_val(f_config):
    assert f_config.zzz is None
    f_config.update('zzz', value=9)

    assert f_config.zzz == 9
    async with aiofiles.open(f_config.fname) as fin:
        text = await fin.read()
        assert "zmq: 9" in text