diff --git a/pyproject.toml b/pyproject.toml index af0ddf7..b6cc162 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "structables" -version = "0.3.6" +version = "0.3.7" authors = [ { name="Private.coffee Team", email="support@private.coffee" }, ] diff --git a/src/structables/main.py b/src/structables/main.py index 7126b6e..f1a1949 100644 --- a/src/structables/main.py +++ b/src/structables/main.py @@ -1,6 +1,8 @@ #!/usr/bin/env python from flask import Flask +import threading +import time from .config import Config from .routes import init_routes @@ -13,11 +15,28 @@ app.typesense_api_key = get_typesense_api_key() init_routes(app) + +def background_update_data(app): + """Runs the update_data function every 5 minutes. + + This replaces the need for a cron job to update the data. + + Args: + app (Flask): The Flask app instance. + """ + while True: + update_data(app) + time.sleep(300) + + def main(): - app.run(port=app.config['PORT'], host=app.config['LISTEN_HOST'], debug=app.config['DEBUG']) + threading.Thread(target=background_update_data, args=(app,), daemon=True).start() + app.run( + port=app.config["PORT"], + host=app.config["LISTEN_HOST"], + debug=app.config["DEBUG"], + ) + if __name__ == "__main__": main() - -# Initialize data when the server starts -update_data(app) \ No newline at end of file