mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-28 00:31:14 +00:00
💥 remove built-in scheduler support
This commit is contained in:
@ -135,7 +135,6 @@ def get_bots() -> Union[NoReturn, Dict[str, Bot]]:
|
||||
return driver.bots
|
||||
|
||||
|
||||
from nonebot.sched import scheduler
|
||||
from nonebot.utils import escape_tag
|
||||
from nonebot.config import Env, Config
|
||||
from nonebot.log import logger, default_filter
|
||||
@ -198,9 +197,6 @@ def init(*, _env_file: Optional[str] = None, **kwargs):
|
||||
logger.debug("Loading nonebot test frontend...")
|
||||
nonebot_test.init()
|
||||
|
||||
if scheduler:
|
||||
_driver.on_startup(_start_scheduler)
|
||||
|
||||
|
||||
def run(host: Optional[str] = None,
|
||||
port: Optional[int] = None,
|
||||
@ -233,13 +229,6 @@ def run(host: Optional[str] = None,
|
||||
get_driver().run(host, port, *args, **kwargs)
|
||||
|
||||
|
||||
async def _start_scheduler():
|
||||
if scheduler and not scheduler.running:
|
||||
scheduler.configure(_driver.config.apscheduler_config)
|
||||
scheduler.start()
|
||||
logger.opt(colors=True).info("<y>Scheduler Started</y>")
|
||||
|
||||
|
||||
from nonebot.plugin import on_message, on_notice, on_request, on_metaevent, CommandGroup
|
||||
from nonebot.plugin import on_startswith, on_endswith, on_keyword, on_command, on_regex
|
||||
from nonebot.plugin import load_plugin, load_plugins, load_builtin_plugins
|
||||
|
@ -262,17 +262,6 @@ class Config(BaseConfig):
|
||||
SESSION_EXPIRE_TIMEOUT=[DD ][HH:MM]SS[.ffffff]
|
||||
SESSION_EXPIRE_TIMEOUT=P[DD]DT[HH]H[MM]M[SS]S # ISO 8601
|
||||
"""
|
||||
apscheduler_config: dict = {"apscheduler.timezone": "Asia/Shanghai"}
|
||||
"""
|
||||
- **类型**: ``dict``
|
||||
- **默认值**: ``{"apscheduler.timezone": "Asia/Shanghai"}``
|
||||
:说明:
|
||||
|
||||
APScheduler 的配置对象,见 `Configuring the Scheduler`_
|
||||
|
||||
.. _Configuring the Scheduler:
|
||||
https://apscheduler.readthedocs.io/en/latest/userguide.html#configuring-the-scheduler
|
||||
"""
|
||||
|
||||
# custom configs
|
||||
# custom configs can be assigned during nonebot.init
|
||||
|
@ -1,45 +0,0 @@
|
||||
"""
|
||||
计划任务
|
||||
========
|
||||
|
||||
计划任务使用第三方库 `APScheduler`_ ,使用文档请参考 `APScheduler使用文档`_ 。
|
||||
|
||||
.. _APScheduler:
|
||||
https://github.com/agronholm/apscheduler
|
||||
.. _APScheduler使用文档:
|
||||
https://apscheduler.readthedocs.io/en/latest/
|
||||
"""
|
||||
|
||||
try:
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
except ImportError:
|
||||
AsyncIOScheduler = None
|
||||
|
||||
if AsyncIOScheduler:
|
||||
scheduler = AsyncIOScheduler()
|
||||
"""
|
||||
:类型:
|
||||
|
||||
``Optional[apscheduler.schedulers.asyncio.AsyncIOScheduler]``
|
||||
|
||||
:说明:
|
||||
|
||||
当可选依赖 ``APScheduler`` 未安装时,``scheduler`` 为 None
|
||||
|
||||
使用 ``pip install nonebot[scheduler]`` 安装可选依赖
|
||||
|
||||
:常用示例:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from nonebot import scheduler
|
||||
|
||||
@scheduler.scheduled_job("cron", hour="*/2", id="xxx", args=[1], kwargs={arg2: 2})
|
||||
async def run_every_2_hour(arg1, arg2):
|
||||
pass
|
||||
|
||||
scheduler.add_job(run_every_day_from_program_start, "interval", days=1, id="xxx")
|
||||
|
||||
"""
|
||||
else:
|
||||
scheduler = None
|
Reference in New Issue
Block a user