File size: 1,289 Bytes
851e5ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""ARQ worker for AI editing.

Runs on its own queue and container so a creator's edit request answers in
seconds even while the main worker is busy rendering. It imports only the
editor and AI modules, not the video pipeline.

Run with: arq src.workers.ai_worker.AIWorkerSettings
"""

import os

# Before observability reads it: logs and errors from here are the AI worker's.
os.environ["SUPOCLIP_SERVICE"] = "ai-worker"

from arq.connections import RedisSettings  # noqa: E402
from arq.worker import func  # noqa: E402

from ..config import Config  # noqa: E402
from ..observability import configure_logging  # noqa: E402
from ..services.ai_edit_service import (  # noqa: E402
    AI_EDIT_QUEUE,
    AI_EDIT_TIMEOUT_SECONDS,
    ai_edit_job,
)

configure_logging()


class AIWorkerSettings:
    config = Config()
    # One try: the browser shows the failure and the creator can resend.
    functions = [func(ai_edit_job, timeout=AI_EDIT_TIMEOUT_SECONDS * 3, max_tries=1, keep_result=0)]
    queue_name = AI_EDIT_QUEUE
    redis_settings = RedisSettings(
        host=config.redis_host, port=config.redis_port, password=config.redis_password, database=0
    )
    # Jobs are network-bound (Claude, Pexels search), so many can run at once.
    max_jobs = 16
    health_check_interval = 30