Files
lukasandClaude Opus 5.5 8a1b9979e9 Productivity features, UI translations, local email translation
- Snooze (with a Snoozed folder), keyboard shortcuts with a Settings
  section, mail templates (Compose > More > Templates), a Subscriptions
  folder with bulk unsubscribe/delete, and tracker blocking with a
  Privacy toggle (on by default)
- Own dialogs instead of browser popups; emoji picker in compose; compose
  windows survive a visit to Settings
- Sentence completion learned from the user's sent mail (no AI)
- Interface in English and Polish (one file per language, English as the
  fallback), picked from the browser on first run, then kept
- Email translation on the server via LibreTranslate: Translate button
  and "Translate to...", messages in several languages translated part
  by part, names/addresses/emoji/file names/phone numbers kept, an
  animated line while translating
- Antispam "Mark as spam" loads with the message, not when the menu opens

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 20:00:31 +02:00

80 lines
2.9 KiB
Python

"""Worker job callables and queue function-sets (refactor §1, §6).
The process is launched via ``workers.run`` (``WORKER_ROLE`` decides which arq
workers run). This module only defines the job callables and the two queue
function-sets; the runner wires them onto the ``interactive`` / ``bulk`` queues.
The sync role runs the coordinator directly (see ``workers.run``), not via arq.
"""
from __future__ import annotations
import logging
import uuid
from typing import Any
from arq import func
from app.completion import build_index_job
from app.indexer.attachments import dedupe_existing_job
from app.outbox.draft_sync import push_draft_to_imap_job, remove_imap_draft_job
from app.outbox.jobs import file_sent_copy_job, send_job
from app.push.service import push_new_mail_job
from app.subscriptions import backfill_list_headers_job
from app.sync.actions import (
ACTION_MAX_TRIES,
delete_thread_job,
empty_folder_job,
move_job,
move_thread_to_folder_job,
push_flags_job,
restore_thread_job,
)
from app.sync.engine import bootstrap_and_backfill, refresh_account_job
logger = logging.getLogger(__name__)
async def sync_bootstrap_account(ctx: dict[str, Any], account_id: str) -> int:
"""Bootstrap + backfill an account (enqueued on account creation)."""
logger.info("sync.bootstrap_account start account=%s", account_id)
count = await bootstrap_and_backfill(uuid.UUID(account_id))
logger.info("sync.bootstrap_account done account=%s messages=%d", account_id, count)
return count
# Fast, interactive user actions (§6): short timeout, high concurrency. The ones
# pushing a change to the mail server retry (arq ``Retry``) for ~24 hours while
# the server is unreachable — more tries than arq's default of 5 allows.
_RETRYING_ACTIONS: list[Any] = [
push_flags_job,
move_job,
move_thread_to_folder_job,
restore_thread_job,
delete_thread_job,
empty_folder_job,
file_sent_copy_job,
]
INTERACTIVE_FUNCTIONS: list[Any] = [
*(func(job, max_tries=ACTION_MAX_TRIES) for job in _RETRYING_ACTIONS),
send_job,
push_draft_to_imap_job,
remove_imap_draft_job,
refresh_account_job,
push_new_mail_job,
]
# Bulk work (§6): long timeout, low concurrency, isolated from interactive jobs.
BULK_FUNCTIONS = [
sync_bootstrap_account,
# Resumable (each batch is saved), so a long first run may span timeouts.
func(dedupe_existing_job, timeout=6 * 3600),
# Batches are saved as they go, so a run cut short resumes where it stopped.
# No stored result: its job id (one per user) must only block a second run
# while one is queued or running — a kept result would refuse new scans for
# an hour after each one.
func(backfill_list_headers_job, timeout=6 * 3600, keep_result=0),
# Sentence completion: one per user at a time, and none kept (as above).
func(build_index_job, timeout=1800, keep_result=0),
]