fix: clarify sync test limit vs full scan; continue on rate limit
Test button (▶) caps UIDs scanned to N; full sync (↻) reads entire mailbox.
This commit is contained in:
1 parent
16816e9d4e
commit
6840e521dd
2 files changed
+37
-13
No files matched your search
@@ -9,7 +9,11 @@ const DEFAULT_TEST_BATCH = 5
|
||||
|
||||
function formatSyncResult(r: import('../lib/api').SyncRunResult): string {
|
||||
const mode = r.dry_run ? 'Dry-run' : 'Sync'
|
||||
return `${mode}: ${r.messages_forwarded} enviados, ${r.messages_failed} falhas, ${r.messages_matched} match (${r.messages_scanned} lidos)`
|
||||
const limit =
|
||||
r.max_emails != null ? ` (limite teste: ${r.max_emails} lidos)` : ' (completo)'
|
||||
const skipped =
|
||||
r.messages_skipped > 0 ? `, ${r.messages_skipped} já conhecidos` : ''
|
||||
return `${mode}${limit}: ${r.messages_forwarded} enviados, ${r.messages_failed} falhas, ${r.messages_matched} match${skipped} — ${r.messages_scanned} lidos`
|
||||
}
|
||||
|
||||
const EMPTY_FORM: AccountCreate = {
|
||||
@@ -305,11 +309,12 @@ export default function Accounts() {
|
||||
{accounts && accounts.length > 0 && (
|
||||
<div className="mb-4 flex flex-wrap items-center gap-3 text-sm text-gray-600 bg-blue-50 border border-blue-100 rounded-md px-4 py-3">
|
||||
<span>
|
||||
O worker automático só corre com <strong>Conta activa</strong>. Os botões ▶/🧪/↻
|
||||
abaixo são sync <strong>manual</strong> (funcionam mesmo com conta inactiva).
|
||||
O worker automático só corre com <strong>Conta activa</strong>.{' '}
|
||||
<strong>▶</strong> testa os primeiros N emails;{' '}
|
||||
<strong>↻</strong> sync completo (toda a mailbox).
|
||||
</span>
|
||||
<label className="flex items-center gap-1.5 ml-auto">
|
||||
Limite teste:
|
||||
Emails no teste ▶:
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
@@ -372,7 +377,7 @@ export default function Accounts() {
|
||||
<td className="px-4 py-3">
|
||||
<div className="flex items-center justify-end gap-1 flex-wrap">
|
||||
<button
|
||||
title={`Sync teste (${testBatchSize})`}
|
||||
title={`Teste: ler no máximo ${testBatchSize} emails (não é sync completo)`}
|
||||
onClick={() => handleSync(a.id, { max_emails: testBatchSize })}
|
||||
disabled={syncingId === a.id}
|
||||
className="p-1.5 text-gray-400 hover:text-green-600 disabled:opacity-40"
|
||||
@@ -394,7 +399,7 @@ export default function Accounts() {
|
||||
<FlaskConical size={14} />
|
||||
</button>
|
||||
<button
|
||||
title="Sync completo"
|
||||
title="Sync completo — percorre todas as pastas IMAP"
|
||||
onClick={() => handleSync(a.id, {}, true)}
|
||||
disabled={syncingId === a.id}
|
||||
className="p-1.5 text-gray-400 hover:text-indigo-600 disabled:opacity-40"
|
||||
|
||||
@@ -170,7 +170,6 @@ def sync_account(
|
||||
|
||||
allowed_extensions = set(account.allowed_extensions or [])
|
||||
processed_keys = _get_known_message_keys(db, account_id)
|
||||
handled_count = 0
|
||||
stop_all = False
|
||||
|
||||
imap = connect_imap(imap_config)
|
||||
@@ -208,7 +207,7 @@ def sync_account(
|
||||
uids = data[0].split()
|
||||
|
||||
for uid in uids:
|
||||
if max_emails is not None and handled_count >= max_emails:
|
||||
if max_emails is not None and result.messages_scanned >= max_emails:
|
||||
stop_all = True
|
||||
break
|
||||
|
||||
@@ -261,7 +260,6 @@ def sync_account(
|
||||
)
|
||||
processed_keys.add(message_key)
|
||||
result.messages_forwarded += 1
|
||||
handled_count += 1
|
||||
logger.info("DRY_RUN matched: %s", subject)
|
||||
continue
|
||||
|
||||
@@ -291,12 +289,33 @@ def sync_account(
|
||||
)
|
||||
processed_keys.add(message_key)
|
||||
result.messages_forwarded += 1
|
||||
handled_count += 1
|
||||
logger.info("Forwarded: %s", subject)
|
||||
except ForwardRateLimitError as exc:
|
||||
logger.warning("Hourly forward limit reached, stopping sync: %s", exc)
|
||||
stop_all = True
|
||||
break
|
||||
logger.warning(
|
||||
"Hourly forward limit reached, skipping forward (scan continues): %s",
|
||||
exc,
|
||||
)
|
||||
message_row = _upsert_message(
|
||||
db,
|
||||
account_id=account_id,
|
||||
message_key=message_key,
|
||||
folder=folder,
|
||||
uid=uid_str,
|
||||
subject=subject,
|
||||
from_addr=from_addr,
|
||||
date=date,
|
||||
status=MessageStatus.failed,
|
||||
error_message=str(exc),
|
||||
)
|
||||
_record_forward_attempt(
|
||||
db,
|
||||
message=message_row,
|
||||
success=False,
|
||||
dry_run=False,
|
||||
error_message=str(exc),
|
||||
)
|
||||
processed_keys.add(message_key)
|
||||
result.messages_failed += 1
|
||||
except Exception as exc:
|
||||
error_text = str(exc)
|
||||
logger.error("Forward failed for %s: %s", subject, error_text)
|
||||
|
||||
Reference in new issue
Block a user