Spaces:
Running
Running
File size: 817 Bytes
d58f064 8bbf39f d58f064 8bbf39f fe44f75 ee73e80 8bbf39f d58f064 7f240e1 d58f064 4d1dae1 8bbf39f 6b25ec8 fe44f75 d58f064 e5f4377 8bbf39f fe44f75 d58f064 fe44f75 832b35a 2946aac 2cd02e7 d58f064 2cd02e7 07cb7a4 d58f064 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import time
import os
import datetime
import requests
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi_utilities import repeat_at
my_data = list( str('-') * 10 )
START_STAT_URL = os.getenv('START_STAT_URL', '')
@asynccontextmanager
async def lifespan(app: FastAPI):
# --- startup ---
work()
# send stat info
if START_STAT_URL:
requests.get(f'{START_STAT_URL}?add=HF_der-opt_worker_start_event')
yield
# --- shutdown ---
app = FastAPI(lifespan=lifespan)
@repeat_at(cron="*/15 * * * *")
def work():
now_dtime = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
my_data.append(now_dtime)
my_data.pop(0) # trim old values
print('-= work! =-')
@app.get("/")
def read_root():
return {"my_data": my_data} |