Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tg post NetError and update docker compose deploy #28

Merged
merged 1 commit into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ cython_debug/
*.mkv

/deploy/docker/
/deploy/allinone/

/store.json
/conf/store.json
Expand Down
33 changes: 18 additions & 15 deletions animepipeline/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,24 @@ async def pipeline_post(self, task_info: TaskInfo) -> None:

self.qbittorrent_manager.add_torrent(torrent_hash=torrent_file_hash, torrent_file_path=torrent_file_save_path)

logger.info(f"Generate all post info files for {task_info.name} EP {task_info.episode} ...")

try:
post_template = PostTemplate(
video_path=finalrip_downloaded_path,
bangumi_url=task_info.bangumi, # type: ignore
chinese_name=task_info.translation,
uploader="TensoRaws",
)

post_template.save(
html_path=Path(task_info.download_path) / (finalrip_downloaded_path.name + ".html"),
markdown_path=Path(task_info.download_path) / (finalrip_downloaded_path.name + ".md"),
bbcode_path=Path(task_info.download_path) / (finalrip_downloaded_path.name + ".txt"),
)
except Exception as e:
logger.error(f"Failed to generate post info files: {e}")

logger.info(f"Post to Telegram Channel for {task_info.name} EP {task_info.episode} ...")

if self.tg_channel_sender is None:
Expand All @@ -282,21 +300,6 @@ async def pipeline_post(self, task_info: TaskInfo) -> None:
)
await self.tg_channel_sender.send_text(text=tg_text)

logger.info(f"Generate all post info files for {task_info.name} EP {task_info.episode} ...")

post_template = PostTemplate(
video_path=finalrip_downloaded_path,
bangumi_url=task_info.bangumi, # type: ignore
chinese_name=task_info.translation,
uploader="TensoRaws",
)

post_template.save(
html_path=Path(task_info.download_path) / (finalrip_downloaded_path.name + ".html"),
markdown_path=Path(task_info.download_path) / (finalrip_downloaded_path.name + ".md"),
bbcode_path=Path(task_info.download_path) / (finalrip_downloaded_path.name + ".txt"),
)

# update task status
task_status.posted = True
await self.json_store.update_task(task_info.hash, task_status)
11 changes: 9 additions & 2 deletions animepipeline/post/tg.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,22 @@ def __init__(self, config: TelegramConfig) -> None:
self.bot = Bot(token=config.bot_token)
self.channel_id = config.channel_id

@retry(wait=wait_random(min=3, max=15), stop=stop_after_attempt(5))
@retry(wait=wait_random(min=3, max=15), stop=stop_after_attempt(10))
async def send_text(self, text: str) -> None:
"""
Send text to the channel.

:param text: The text to send.
"""
try:
await self.bot.send_message(chat_id=self.channel_id, text=text)
await self.bot.send_message(
chat_id=self.channel_id,
text=text,
read_timeout=60,
write_timeout=60,
connect_timeout=60,
pool_timeout=600,
Comment on lines +31 to +34
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (performance): The timeout values seem unnecessarily high for a Telegram message operation

Consider reducing these timeout values. 600 seconds for pool_timeout and 60 seconds for other timeouts might be excessive for sending a message.

Suggested change
read_timeout=60,
write_timeout=60,
connect_timeout=60,
pool_timeout=600,
read_timeout=10,
write_timeout=10,
connect_timeout=10,
pool_timeout=30,

)
except telegram.error.NetworkError as e:
logger.error(f"Network error: {e}, text: {text}")
raise e
Expand Down
25 changes: 18 additions & 7 deletions deploy/docker-compose-animepipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@ version: "3.8"

name: animepipeline

networks:
backend:
driver: bridge

services:
animepipeline:
image: lychee0/animepipeline:latest
restart: always
volumes:
- ./animepipeline:/app/conf
- ./downloads:/downloads
networks:
- backend

qb:
image: superng6/qbittorrentee:4.4.5.10
image: linuxserver/qbittorrent:latest
restart: always
environment:
- PUID=1026
Expand All @@ -28,4 +22,21 @@ services:
ports:
- "6881:6881"
- "6881:6881/udp"
- "48008:48008"
- "48008:48008/udp"
- "8091:8080"
# qb-ee:
# image: superng6/qbittorrentee:4.4.5.10
# restart: always
# environment:
# - PUID=1026
# - PGID=100
# volumes:
# - ./allinone/qb-config:/config
# - ./downloads:/downloads
# ports:
# - "6881:6881"
# - "6881:6881/udp"
# - "48008:48008"
# - "48008:48008/udp"
# - "8091:8080"
6 changes: 2 additions & 4 deletions deploy/docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ version: "3.8"

name: animepipeline-dev

networks:
backend:
driver: bridge

services:
qb:
image: superng6/qbittorrentee:4.4.5.10
Expand All @@ -19,4 +15,6 @@ services:
ports:
- "6881:6881"
- "6881:6881/udp"
- "48008:48008"
- "48008:48008/udp"
- "8091:8080"