async def resume_job(job: JobId):
    try:
        scheduler.resume_job(job.id)
        return {'result': 'succ'}
    except Exception as e:
        logger.error(e)
        raise HTTPException(status_code=404, detail="id not found")
async def add_job(job: JobId):
    # 添加调度任务
    query = sche.select().where(sche.c.id == job.id)
    result = await database.fetch_one(query)
    result_dict = dict(result)
    job_id = f'{job.id}_{int(time.time())}'
    try:
        scheduler.add_job(
            result_dict.get('script_name'),
            trigger='cron',
            id=job_id,
            name=result_dict.get('schedule_name'),
            misfire_grace_time=60 * 60,
            coalesce=True,
            max_instances=999,
            second=result_dict.get("cron_second"),
            minute=result_dict.get("cron_minutes"),
            hour=result_dict.get("cron_hour"),
            day=result_dict.get("cron_day_of_month"),
            day_of_week=result_dict.get("cron_day_of_week"),
            month=result_dict.get("cron_month"),
        )
        return {'result': 'succ'}
    except Exception as e:
        logger.error(e)
        raise HTTPException(status_code=404, detail="id not found")
async def startup():
    global conn, bgsrv, scheduler

    try:
        conn = rpyc.connect("localhost", 12345)
        # create a bg thread to process incoming events
        bgsrv = rpyc.BgServingThread(conn)
        scheduler = conn.root
    except ConnectionRefusedError as e:
        logger.error("请先执行 rpc_server.py,否则无法使用web")
        raise
    await database.connect()
async def reschedule_job(job: UpdateJob):
    try:
        scheduler.reschedule_job(job_id=job.id,
                                 trigger='cron',
                                 second=job.cron_second,
                                 minute=job.cron_minutes,
                                 hour=job.cron_hour,
                                 day=job.cron_day_of_month,
                                 day_of_week=job.cron_day_of_week,
                                 month=job.cron_month)
        return {'result': 'succ'}
    except Exception as e:
        logger.error(e)
        raise HTTPException(status_code=404, detail="id not found")