Skip to content

Commit

Permalink
Merge branch 'refs/heads/rewrite-monitor-flexibility-robustness' into…
Browse files Browse the repository at this point in the history
… dev
  • Loading branch information
Rongronggg9 committed Jun 24, 2024
2 parents 1fc8bf1 + c231cff commit 94198f0
Show file tree
Hide file tree
Showing 25 changed files with 1,431 additions and 435 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Enhancements

- **Rewritten monitor**: The feed monitor has been rewritten for flexibility and robustness. It is now more memory-efficient and can smooth out spikes in CPU usage.
- **Print Telegram user info of bot**: Print the bot's Telegram user info when the bot is started. This is to help bot managers to find the bot's username and user ID when deploying the bot.
- **Minor refactor**: Some internal functions have been refactored to improve performance and maintainability.

Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### 增强

- **重写的监视器**: Feed 监视器已被重写,以提高灵活性和稳健性。它现在更节省内存,并且可以平滑 CPU 使用率的波动。
- **打印 bot 的 Telegram 用户信息**: 在 bot 启动时打印 bot 的 Telegram 用户信息。这是为了帮助 bot 管理员在部署 bot 时找到 bot 的用户名和用户 ID。
- **次要的重构**: 重构了一些内部函数以提高性能和可维护性。

Expand Down
15 changes: 13 additions & 2 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
from random import sample

from . import log, db, command
from .monitor import Monitor
from .i18n import i18n, ALL_LANGUAGES, get_commands_list
from .parsing import tgraph
from .helpers.bg import bg
from .helpers.queue import queued

# log
logger = log.getLogger('RSStT')
Expand All @@ -36,6 +39,7 @@
bot: Optional[TelegramClient] = None
pre_tasks = []

monitor = Monitor()
scheduler = AsyncIOScheduler(event_loop=loop)


Expand All @@ -53,6 +57,8 @@ def init():
pre_tasks.extend((
loop.create_task(db.init()),
loop.create_task(tgraph.init()),
loop.create_task(bg.init(loop=loop)),
loop.create_task(queued.init(loop=loop)),
))

if env.PORT:
Expand Down Expand Up @@ -257,7 +263,12 @@ async def lazy():

async def post():
logger.info('Exiting gracefully...')
tasks = [asyncio.shield(loop.create_task(db.close())), loop.create_task(tgraph.close())]
tasks = [
asyncio.shield(loop.create_task(db.close())),
loop.create_task(tgraph.close()),
loop.create_task(bg.close()),
loop.create_task(queued.close()),
]
if scheduler.running:
scheduler.shutdown(wait=False)
if bot and bot.is_connected():
Expand Down Expand Up @@ -315,7 +326,7 @@ def main():

loop.create_task(lazy())

scheduler.add_job(func=command.monitor.run_monitor_task,
scheduler.add_job(func=monitor.run_periodic_task,
trigger=CronTrigger(minute='*', second=env.CRON_SECOND, timezone='UTC'),
max_instances=10,
misfire_grace_time=10)
Expand Down
2 changes: 1 addition & 1 deletion src/command/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from __future__ import annotations

from . import opml, sub, utils, monitor, customization, administration, misc
from . import opml, sub, utils, customization, administration, misc
Loading

0 comments on commit 94198f0

Please sign in to comment.