Skip to content
This repository was archived by the owner on Nov 10, 2024. It is now read-only.
This repository was archived by the owner on Nov 10, 2024. It is now read-only.

[BUG] repeat_every does not work as expected when not also annotated with the fastapi startup event #138

@nonathaj

Description

@nonathaj

Describe the bug
If you use the repeat_every decorator without app.on_event("startup"), it requires calling in an async context to actually add to loop to asyncio. You can also get it to work by awaiting the resulting decorated function after the fact.

from fastapi_restful.tasks import repeat_every

@repeat_every(seconds=60)
def do_stuff():
    """ this is never called """

It must be called from an async context

from fastapi import FastAPI
from fastapi_restful.tasks import repeat_every

app = FastAPI()

@app.on_event("startup")  # runs the decoration once, adding the loop to asyncio
@repeat_every(seconds=60)
def do_stuff():
    """ this is never called """

Expected behavior
The decorated function is repeatedly called without

Environment:

  • OS: Any (I repro'd on Linux)
  • FastAPI Utils, FastAPI, and Pydantic versions [e.g. 0.3.0], get them with:
fastapi_restful version: 0.4.3
fastapi version: 0.74.0
             pydantic version: 1.9.0
            pydantic compiled: True
               python version: 3.9.0 (default, Jun  4 2021, 15:43:34)  [GCC 8.3.1 20190311 (Red Hat 8.3.1-3)]
                     platform: Linux-3.10.0-1160.45.1.el7.x86_64-x86_64-with-glibc2.17
     optional deps. installed: ['dotenv', 'typing-extensions']

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions