You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
970 B
31 lines
970 B
# -*- coding: utf-8 -*-
|
|
# @Time : 2023/10/24 19:43
|
|
# @Author : tx
|
|
# @File : empty_drug.py.py
|
|
# @Description : 每日定时任务,满一年空瓶药剂进行删除
|
|
|
|
import httpx
|
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
|
from pytz import timezone
|
|
from datetime import datetime, timedelta
|
|
from tortoise.queryset import QuerySet
|
|
|
|
from conf import setting
|
|
from helper.logger import logger
|
|
from models import Drug, DrugStateEnum
|
|
|
|
async def empty_drug_job():
|
|
"""
|
|
满一年空瓶药剂条目删除
|
|
:return:
|
|
"""
|
|
now_time = datetime.now()
|
|
one_year_ago = now_time - timedelta(days=365)
|
|
await Drug.filter(state=DrugStateEnum.EMPTY, update_at__lt=one_year_ago).all().delete()
|
|
|
|
|
|
def start_empty_scheduler():
|
|
"""启动定时任务,每日1点执行"""
|
|
scheduler = AsyncIOScheduler(timezone=timezone('Asia/Shanghai'))
|
|
scheduler.add_job(empty_drug_job, 'cron', day_of_week='*', hour='1', minute='0')
|
|
scheduler.start() |