Giter Site home page Giter Site logo

Comments (6)

vorenhoutgithub avatar vorenhoutgithub commented on June 3, 2024 1

The documentation is here https://fastapi.tiangolo.com/advanced/events/#async-context-manager
Can you also add that to the docs here?

from fastapi-utilities.

priyanshu-panwar avatar priyanshu-panwar commented on June 3, 2024

The functions repeat_at and repeat_every work for the time being after the depreciation of the alternative events like app.on_startup().
I'll try to figure out a solution for this issue asap. Need to add our functions in the lifespan of the app.

from fastapi-utilities.

cm-halfspace avatar cm-halfspace commented on June 3, 2024

Any update on this?

from fastapi-utilities.

mareksDev avatar mareksDev commented on June 3, 2024

This library seems exactly the right solution to my problem, but yes, exactly the same concern that it is not possible to use it with the newest version. Are there any updates or an expected time when there might be an update?

from fastapi-utilities.

priyanshu-panwar avatar priyanshu-panwar commented on June 3, 2024

I found a workaround for this.

from fastapi import FastAPI
from contextlib import asynccontextmanager
from fastapi_utilities.repeat import repeat_every, repeat_at


@asynccontextmanager
async def lifespan(app: FastAPI):
    # --- startup ---
    await test()
    test2()
    yield
    # --- shutdown ---


app = FastAPI(lifespan=lifespan)


# Repeat Every Example
@repeat_every(seconds=2)
async def test():
    print("test")

# Repeat At Example
@repeat_at(cron="* * * * *")
def test2():
    print("test2")

This works fine.
We need to useasynccontextmanager.
Only difference is to call our tasks from lifespan function instead of using on_event function.
Till then please use this and let me know the reviews.

from fastapi-utilities.

priyanshu-panwar avatar priyanshu-panwar commented on June 3, 2024

I feel this solution is enough for us.
@mareksDev @cm-halfspace @vorenhoutgithub Please let me know and merge the above PR.

from fastapi-utilities.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.