gawel / aiocron

Crontabs for asyncio
MIT License
343 stars 21 forks source link

Crontab stopped running #34

Open Olesp opened 1 year ago

Olesp commented 1 year ago

I've created a crontab in my code and deployed it to a server. Everything ran fine until one month ago i'd say. Now my code run, but the crontab never get run. No idea why. I'll provide as much info as needed. Infos : Python 3.10.6

Modules: aiocron-1.8 pyairtable-1.3.0 Jinja2-3.1.2 discord.py-2.0.1 aiohttp aiofiles

@aiocron.crontab("*15 * * * *")
async def gather_new_missions():
    doing stuff here

If you have any idea, even running it locally with cron set to everyminute doesn't do anything

gawel commented 1 year ago

Probably a dupplicate of a known issue with aiohttp See https://github.com/gawel/aiocron/issues/21

Olesp commented 1 year ago

I'm not sure to understand the issue you linked. It used to work, even when I don't even use the aiohttp in the cron function. Could you please explain how this module impact my code after working for a while ?

gawel commented 1 year ago

aiohttp use a new event loop when none is specified. this break coroutines initiated with the original event loop

https://github.com/aio-libs/aiohttp/blob/master/aiohttp/web.py#L487

just use web.run_app(loop=asyncio.get_eventloop())

Olesp commented 1 year ago
@aiocron.crontab("*/15 * * * *")
async def gather_new_missions():
    print("test")
    # do stuff here
     async with aiohttp.ClientSession() as session:
          url = "example.com"
          async with session.get(url) as resp:
              if resp.status == 200:
                  f = await aiofiles.open(filename, mode="wb")
                  await f.write(await resp.read())
                  await f.close()

So this code wouldn't even print "test" because of aiohttp way of implementing a loop ? I don't quite understand how the code you've linked above could help me here.

gawel commented 1 year ago

Yeah it's hard to help here. I'm trying. But I have no other clue

Everything seems to work with 3.10 so the problem should be on your side. Related to your code or a third-party library

https://github.com/gawel/aiocron/actions/runs/3376501956/jobs/5604299015