All checks were successful
continuous-integration/drone/push Build is passing
32 lines
932 B
Python
32 lines
932 B
Python
import os
|
|
from flask import Flask
|
|
from misc import currDay
|
|
from db import db, Period, Event
|
|
from create_events import createEvents
|
|
from apscheduler.schedulers.background import BlockingScheduler
|
|
from apscheduler.triggers.cron import CronTrigger
|
|
|
|
basedir = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
app = Flask(__name__)
|
|
app.config['SECRET_KEY'] = os.environ['SECRET_KEY']
|
|
app.config['SQLALCHEMY_DATABASE_URI'] =\
|
|
'sqlite:///' + os.path.join(basedir, os.environ['SQLITE_DB'])
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
db.init_app(app)
|
|
|
|
# declare BlockingScheduler
|
|
sched = BlockingScheduler()
|
|
|
|
# run createEvents upon app launch
|
|
with app.app_context():
|
|
createEvents(db, currDay, Period, Event)
|
|
|
|
def eventsTask():
|
|
with app.app_context():
|
|
createEvents(db, currDay, Period, Event)
|
|
sched.add_job(eventsTask, CronTrigger.from_crontab('00 * * * *'))
|
|
print("Background worker started")
|
|
sched.start()
|
|
|