(app, loop)
| 69 | |
| 70 | @app.listener("before_server_start") |
| 71 | async def initialize_scheduler(app, loop): |
| 72 | # Check that tables exist |
| 73 | await db.gino.create_all() |
| 74 | |
| 75 | # Schedule exchangerate updates |
| 76 | try: |
| 77 | _ = open("scheduler.lock", "w") |
| 78 | fcntl.lockf(_.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) |
| 79 | |
| 80 | scheduler = AsyncIOScheduler() |
| 81 | scheduler.start() |
| 82 | |
| 83 | # Updates lates 90 days data |
| 84 | scheduler.add_job(update_rates, "interval", hours=1) |
| 85 | |
| 86 | # Fill up database with rates |
| 87 | count = await db.func.count(ExchangeRates.date).gino.scalar() |
| 88 | scheduler.add_job(update_rates, kwargs={"historic": True}) |
| 89 | except BlockingIOError: |
| 90 | pass |
| 91 | |
| 92 | |
| 93 | @app.middleware("request") |
nothing calls this directly
no outgoing calls
no test coverage detected