Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,17 +10,18 @@ my_data = list( str('-') * 10 )
|
|
| 10 |
@asynccontextmanager
|
| 11 |
async def lifespan(app: FastAPI):
|
| 12 |
# --- startup ---
|
| 13 |
-
work()
|
| 14 |
yield
|
| 15 |
# --- shutdown ---
|
| 16 |
|
| 17 |
app = FastAPI(lifespan=lifespan)
|
| 18 |
|
| 19 |
-
@repeat_at(cron="
|
| 20 |
def work():
|
| 21 |
now_dtime = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
|
| 22 |
my_data.append(now_dtime)
|
| 23 |
my_data.pop(0) # trim old values
|
|
|
|
| 24 |
|
| 25 |
@app.get("/")
|
| 26 |
def read_root():
|
|
|
|
| 10 |
@asynccontextmanager
|
| 11 |
async def lifespan(app: FastAPI):
|
| 12 |
# --- startup ---
|
| 13 |
+
work() # no await!
|
| 14 |
yield
|
| 15 |
# --- shutdown ---
|
| 16 |
|
| 17 |
app = FastAPI(lifespan=lifespan)
|
| 18 |
|
| 19 |
+
@repeat_at(cron="*/15 * * * *")
|
| 20 |
def work():
|
| 21 |
now_dtime = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
|
| 22 |
my_data.append(now_dtime)
|
| 23 |
my_data.pop(0) # trim old values
|
| 24 |
+
print('-= work! =-')
|
| 25 |
|
| 26 |
@app.get("/")
|
| 27 |
def read_root():
|