GithubHelp home page GithubHelp logo

Comments (1)

minsis avatar minsis commented on May 28, 2024 1

This is a known issue celery/celery#4806. The gist of it is that when a change is made to any one of your scheduled tasks, beat then reloads the table to make sure everything is current. In doing so it also ends up checking the last_ran_at timestamp and if too much time has elapsed it schedules it for execution. There's some logic issues with how that works. There's a larger work around in the same issue that you can use if you want to fork your own copy. Note that this can also happen if you restart beat in the same timeframe.

The way I've been able to work around it, on start up or changes made to any one of my scheduled entries, I basically just set last_run_at to null. As the logic for last_run_at wont trigger an execution if its the 'first time'. Of course this creates an issue if you actually care about the last execution time. Here my use case it doesn't matter to have this viewable by anyone as I have flower to track all my tasks executions as well as a custom audit table.

This is what my start up of beat looks like (replace SessionManager() with whatever your db connection is):

@beat_init.connect
def reset_last_run(**_):
    """
    Reset all the last ran times in celery database. This is to prevent accidental runs if a new service is deployed
    or restarted.
    """

    logging.info("Resetting last run at for Periodic Task table")
    with SessionManager() as session:
        periodic_tasks = session.query(PeriodicTask).all()
        for pt in periodic_tasks:
            pt.last_run_at = None
            session.add(pt)
        session.commit()

from celery-sqlalchemy-scheduler.

Related Issues (20)

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.