feat(translation): pooled Interpreter session + manual sweep resumes after drain
- interpreter_client: shared requests.Session with a connect-only retry (connect=2, no status retries — we map 429/5xx ourselves) so a proxy reload is smoothed and the keep-alive connection is pooled across the sweep. - translate_posts: on an interrupt (drain), re-enqueue after the Retry-After hint / default backoff instead of waiting for the daily beat; self-terminates via the health gate. Steady-state one-chunk-per-run on success is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -70,10 +70,21 @@ def translate_posts() -> str:
|
||||
return ready
|
||||
base_url, target = ready
|
||||
posts = _select_untranslated(session, None, _MAX_POSTS_PER_RUN)
|
||||
# Steady-state daily sweep: one chunk per run. On interruption the
|
||||
# untranslated rows stay NULL and the next daily beat (or a fresh
|
||||
# "Translate now") resumes them — no self-chase needed here.
|
||||
status, translated, _retry = _translate_batch(session, posts, base_url, target)
|
||||
status, translated, retry_after = _translate_batch(
|
||||
session, posts, base_url, target,
|
||||
)
|
||||
# Steady-state daily sweep: one chunk per run on success (the beat drives
|
||||
# the rest — no tail-chase). But if Interpreter drained mid-chunk, don't
|
||||
# make a manual "Translate now" wait a whole day — re-enqueue after its
|
||||
# Retry-After hint (or the default backoff). Self-terminating: once the
|
||||
# service is down the health gate returns "interpreter unavailable" early.
|
||||
if status == "interrupted" and _count_untranslated(session, None):
|
||||
delay = _interrupt_backoff(retry_after)
|
||||
translate_posts.apply_async((), {}, countdown=delay)
|
||||
log.info(
|
||||
"translate_posts: interrupted (service draining) → retry in %ss",
|
||||
delay,
|
||||
)
|
||||
return _summary(status, translated, len(posts))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user