gawel / aiocron

Crontabs for asyncio
MIT License
343 stars 21 forks source link

Every 3 seconds cron job not working #35

Closed liho00 closed 1 year ago

liho00 commented 1 year ago
import asyncio
from datetime import datetime
import aiocron

# loop = asyncio.new_event_loop()

async def foo(param):
    print(datetime.now().time(), param)

async def main():
    # cron_sec = aiocron.crontab(
    #     '*/1 * * * * *', func=foo, args=("At every minute",), start=True, loop=loop)
    cron_every_3_sec = aiocron.crontab(
        '*/3 * * * * *', func=foo, args=("At every second 3",), start=True, )

    while True:
        await asyncio.sleep(1)

asyncio.run(main())

Output

13:36:40.001395 At every second 3
13:36:41.001332 At every second 3
13:36:42.000278 At every second 3
13:36:43.001380 At every second 3
13:36:44.001389 At every second 3
13:36:45.001406 At every second 3
13:36:46.000702 At every second 3
13:36:47.000482 At every second 3
13:36:48.000483 At every second 3
image

I set the cron to be executed every 3 seconds, however the job running every second...

look like this library does not support seconds based cron job? Would you give me some though how to implement seconds based cron job? I am willing to pr as well. thanks in advance!

Python 3.9.12 aiocron-1.8

liho00 commented 1 year ago

Ah ha I found why, i am using /3 following https://crontab.cronhub.io/

however, croniter using other format /3 as every x second...