fix(knowledge-base): 优化知识库页面,重构后端job队列
This commit is contained in:
1 parent
7e4a2037d8
commit
b476b58a91
38 files changed
+992
-428
No files matched your search
@@ -0,0 +1,61 @@
|
||||
"""
|
||||
tests/jobs/test_store.py
|
||||
|
||||
用途:验证 store.claim_next 归一化与空队列行为。
|
||||
"""
|
||||
from app.jobs.store import _normalize_kb_job
|
||||
from app.jobs.types import JobType
|
||||
from app.models import KbJob
|
||||
|
||||
|
||||
def test_normalize_kb_job_clean(app):
|
||||
with app.app_context():
|
||||
job = KbJob(
|
||||
job_type='clean',
|
||||
status='running',
|
||||
progress=1,
|
||||
payload_json={'document_version_id': 42},
|
||||
)
|
||||
normalized = _normalize_kb_job(job)
|
||||
assert normalized['id'] == job.id
|
||||
assert normalized['job_type'] == JobType.KB_CLEAN
|
||||
assert normalized['raw_job_type'] == 'clean'
|
||||
assert normalized['payload']['job_id'] == job.id
|
||||
assert normalized['payload']['document_version_id'] == 42
|
||||
|
||||
|
||||
def test_normalize_kb_job_sync_dify(app):
|
||||
with app.app_context():
|
||||
job = KbJob(job_type='sync_dify', status='running', progress=1)
|
||||
normalized = _normalize_kb_job(job)
|
||||
assert normalized['job_type'] == JobType.KB_DIFY_SYNC
|
||||
|
||||
|
||||
def test_claim_next_returns_none_when_empty(app):
|
||||
from app.jobs import store
|
||||
|
||||
with app.app_context():
|
||||
assert store.claim_next(queues=['kb']) is None
|
||||
|
||||
|
||||
def test_find_shipping_notice_job_id_matches_task_no(app):
|
||||
from app import db
|
||||
from app.jobs.queue import _find_shipping_notice_job_id
|
||||
|
||||
with app.app_context():
|
||||
target = KbJob(
|
||||
job_type=JobType.SHIPPING_NOTICE_RUN.value,
|
||||
status='queued',
|
||||
progress=0,
|
||||
payload_json={'task_no': 'SHIP-A'},
|
||||
)
|
||||
newer_other = KbJob(
|
||||
job_type=JobType.SHIPPING_NOTICE_RUN.value,
|
||||
status='queued',
|
||||
progress=0,
|
||||
payload_json={'task_no': 'SHIP-B'},
|
||||
)
|
||||
db.session.add_all([target, newer_other])
|
||||
db.session.commit()
|
||||
|
||||
assert _find_shipping_notice_job_id('ship-a') == target.id
|
||||
Reference in new issue
Block a user