-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add Async worker to decouple API and core logic #69
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a6f2498
chore: add idea configurations
aturret 012e99c
doc: update CLAUDE.md
aturret aa02195
feat: refactor async message queue for telegrambot
aturret fc0cc0a
feat: add unit tests
aturret 1a6c670
fix: weibo retweet variable type issue
aturret File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...a/runConfigurations/fullstack_polling.xml → ...nConfigurations/fullstack_polling_api.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 11 additions & 24 deletions
35
apps/api/src/services/file_export/audio_transcribe/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,16 @@ | ||
| import asyncio | ||
| """API-layer audio transcription — wraps the shared AudioTranscribe with API config.""" | ||
|
|
||
| from src.config import DOWNLOAD_VIDEO_TIMEOUT | ||
| from fastfetchbot_shared.services.file_export.audio_transcribe import AudioTranscribe as BaseAudioTranscribe | ||
| from src.services.celery_client import celery_app | ||
| from fastfetchbot_shared.utils.logger import logger | ||
| from src.config import DOWNLOAD_VIDEO_TIMEOUT | ||
|
|
||
|
|
||
| class AudioTranscribe: | ||
| def __init__(self, audio_file: str): | ||
| self.audio_file = audio_file | ||
| class AudioTranscribe(BaseAudioTranscribe): | ||
| """API AudioTranscribe that injects the API's Celery app and timeout.""" | ||
|
|
||
| async def transcribe(self): | ||
| return await self._get_audio_text(self.audio_file) | ||
|
|
||
| @staticmethod | ||
| async def _get_audio_text(audio_file: str): | ||
| logger.info(f"submitting transcribe task: {audio_file}") | ||
| result = celery_app.send_task("file_export.transcribe", kwargs={ | ||
| "audio_file": audio_file, | ||
| }) | ||
| try: | ||
| response = await asyncio.to_thread(result.get, timeout=int(DOWNLOAD_VIDEO_TIMEOUT)) | ||
| return response["transcript"] | ||
| except Exception: | ||
| logger.exception( | ||
| f"file_export.transcribe task failed: audio_file={audio_file}, " | ||
| f"timeout={DOWNLOAD_VIDEO_TIMEOUT}" | ||
| ) | ||
| raise | ||
| def __init__(self, audio_file: str): | ||
| super().__init__( | ||
| audio_file=audio_file, | ||
| celery_app=celery_app, | ||
| timeout=DOWNLOAD_VIDEO_TIMEOUT, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: aturret/FastFetchBot
Length of output: 528
🏁 Script executed:
Repository: aturret/FastFetchBot
Length of output: 851
🏁 Script executed:
Repository: aturret/FastFetchBot
Length of output: 1420
🏁 Script executed:
Repository: aturret/FastFetchBot
Length of output: 202
🏁 Script executed:
Repository: aturret/FastFetchBot
Length of output: 1415
🏁 Script executed:
Repository: aturret/FastFetchBot
Length of output: 2745
Use explicit
Optionaltype annotation forhtml_string.Line 25 has
html_string: str = Nonewhich triggers Ruff RUF013. Since the project targets Python 3.12, usestr | Noneinstead to follow PEP 604 union syntax and satisfy black formatting standards.✏️ Suggested change
📝 Committable suggestion
🧰 Tools
🪛 Ruff (0.15.6)
[warning] 25-25: PEP 484 prohibits implicit
OptionalConvert to
T | None(RUF013)
🤖 Prompt for AI Agents