2022-07-26 10:07:31 +00:00
|
|
|
# jobs 目录
|
|
|
|
|
|
|
|
## 说明
|
|
|
|
|
|
|
|
改目录存放 BOT 的工作队列、注册和具体实现
|
|
|
|
|
|
|
|
## 基础代码
|
|
|
|
|
|
|
|
``` python
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
from telegram.ext import CallbackContext
|
|
|
|
|
|
|
|
from logger import Log
|
|
|
|
from utils.job.manager import listener_jobs_class
|
|
|
|
|
|
|
|
@listener_jobs_class()
|
|
|
|
class JobTest:
|
|
|
|
|
|
|
|
@classmethod
|
2022-08-04 12:58:12 +00:00
|
|
|
def build_jobs(cls, job_queue: JobQueue):
|
2022-07-26 10:07:31 +00:00
|
|
|
test = cls()
|
|
|
|
# 注册每日执行任务
|
|
|
|
# 执行时间为21点45分
|
2022-08-04 12:58:12 +00:00
|
|
|
job_queue.run_daily(test.test, datetime.time(21, 45, 00), name="测试Job")
|
2022-07-26 10:07:31 +00:00
|
|
|
|
|
|
|
async def test(self, context: CallbackContext):
|
|
|
|
Log.info("测试Job[OK]")
|
|
|
|
```
|
|
|
|
|
|
|
|
### 注意
|
|
|
|
|
|
|
|
jobs 模块下的类必须提供 `build_jobs` 类方法作为构建相应处理程序给 `handle.py`
|
|
|
|
|
|
|
|
只需在构建的类前加上 `@listener_jobs_class()` 修饰器即可
|