test_ken_dev

Untitled

Jan 24th, 2025
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | Software | 0 0
  1. from flask import Flask
  2. from flask_sqlalchemy import SQLAlchemy
  3. from flask_mail import Mail
  4. from flask_migrate import Migrate
  5. from config import Config
  6. from app.celery import celery_init_app
  7. from celery.schedules import crontab
  8.  
  9. db = SQLAlchemy()
  10. mail = Mail()
  11. migrate = Migrate()
  12.  
  13.  
  14. def create_app(config_class=Config):
  15.     app = Flask(__name__)
  16.     app.config.from_object(config_class)
  17.  
  18.     db.init_app(app)
  19.     mail.init_app(app)
  20.     migrate.init_app(app, db)
  21.  
  22.     app.config.from_mapping(
  23.         CELERY=dict(
  24.             broker_url="redis://redis",
  25.             result_backend="redis://redis",
  26.             task_ignore_result=True,
  27.             beat_schedule={
  28.                 "run-daily-sales-data-task": {
  29.                     "task": "app.tasks.fetch_and_process_sales_data",
  30.                     "schedule": crontab(hour=1, minute=0),
  31.                 },
  32.                 "hello-world": {
  33.                     "task": "app.tasks.hello_world",
  34.                     "schedule": crontab(minute="*/1"),
  35.                 },
  36.             },
  37.         ),
  38.     )
  39.  
  40.     from app.routes import register_routes
  41.  
  42.     register_routes(app)
  43.     celery_init_app(app)
  44.  
  45.     return app
  46.  
Advertisement
Add Comment
Please, Sign In to add comment