kbzhishiku
This commit is contained in:
1 parent
7f542f54a5
commit
08a19ebe96
68 files changed
+16602
-229
No files matched your search
@@ -0,0 +1,47 @@
|
||||
"""
|
||||
backend/worker_kb.py
|
||||
文件用途:知识库最小 worker 入口
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import time
|
||||
|
||||
from app import create_app
|
||||
from app.services.knowledge_cleaning.queue_service import process_next_clean_job
|
||||
|
||||
|
||||
def _resolve_config_name() -> str:
|
||||
"""Keep the worker aligned with container/runtime environment selection."""
|
||||
explicit = os.getenv('APP_CONFIG')
|
||||
if explicit:
|
||||
return explicit.strip().lower()
|
||||
|
||||
flask_env = os.getenv('FLASK_ENV', 'production').strip().lower()
|
||||
mapping = {
|
||||
'dev': 'development',
|
||||
'development': 'development',
|
||||
'test': 'testing',
|
||||
'testing': 'testing',
|
||||
'prod': 'production',
|
||||
'production': 'production',
|
||||
}
|
||||
return mapping.get(flask_env, 'production')
|
||||
|
||||
|
||||
def main():
|
||||
app = create_app(_resolve_config_name())
|
||||
poll_seconds = float(app.config.get('KB_WORKER_POLL_SECONDS', 2))
|
||||
|
||||
with app.app_context():
|
||||
print(f'[kb-worker] started, poll_seconds={poll_seconds}')
|
||||
while True:
|
||||
processed, message = process_next_clean_job()
|
||||
if not processed:
|
||||
time.sleep(poll_seconds)
|
||||
continue
|
||||
print(f'[kb-worker] processed job: {message}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in new issue
Block a user