5dc6f29ac1
Neues automation Plugin (app/plugins/builtins/automation/): - 7 DB-Modelle: AgentDefinition, AgentVersion, AutomationDefinition, AutomationVersion, AutomationCronJob, AgentRun, AutomationRun - Migration 0001_initial.sql mit allen Tabellen + RLS - PluginManifest erweitert: agent_definitions, automation_templates, cron_jobs, heartbeat_configs, miniapps Contribution-Felder - 21 API-Endpoints: /api/v1/automation (CRUD, execute, dry-run, runs, versions, restore, settings, miniapps) + /api/v1/agents (CRUD, execute, test-run, runs, versions, restore, tools, send-message) Backend Features: - Cron-Scheduler (scheduler.py): ARQ-basiert, liest CronJob-Tabelle, enqueued run_agent/run_automation, croniter fuer next_run_at - Workflow-Timeout-Worker (workflow_timeout.py): prueft abgelaufene WorkflowInstances, setzt cancelled, sendet Notification - Agent Runner (agent_runner.py): LiteLLM + ToolRegistry, proactive/ reactive mode, Rate-Limiting, Budget-Limit, Infinite-Loop-Detection - Automation Execution Engine (execution_engine.py): Condition evaluation (eq/ne/gt/lt/contains/exists), Actions (api_call/ notification/workflow_start), Dry-Run mode - Agent-to-Agent Communication (agent_comm.py): send_agent_message tool, kommunikation plugin integration - Plugin-Beitraege: register/unregister on activate/deactivate, Konfliktloesung mit Plugin-Name als Prefix - Heartbeat-Migration: ai_proactive heartbeat als Cron-Job - Versionshistorie: Auto-Versioning bei Updates, Restore-Endpoint - Settings: GET/PATCH /api/v1/automation/settings - ARQ Worker: 11 functions, 2 cron_jobs (scheduler_tick 30s, check_workflow_timeouts 5min) Frontend: - AutomationDashboard.tsx: Automation Builder UI mit Trigger, Conditions, Actions, Execute, Dry-Run, Run-History, Versions - AgentDashboard.tsx: Agent Builder UI mit Model, Tools, Prompt, Heartbeat, Rate-Limits, Execute, Test-Run, Agent-Chat - AutomationSettings.tsx: Settings + MiniApp-Builder - automation.ts: 24 React Query Hooks - automation.ts types: TypeScript Interfaces - routes/index.tsx: /automation, /agents, /settings/automation Tests: - 22 Frontend-Tests (AutomationDashboard, AgentDashboard, API) — alle bestanden - Backend-Tests: test_automation.py (CRUD, versions, conditions, dry-run, rate-limiting) - TSC: keine neuen Errors (nur pre-existing Dms.tsx) - croniter dependency installiert
83 lines
2.4 KiB
Python
83 lines
2.4 KiB
Python
"""ARQ worker configuration and entrypoint."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from typing import Any
|
|
|
|
from arq.connections import RedisSettings
|
|
from arq import cron
|
|
|
|
from app.config import get_settings
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def _get_redis_settings() -> RedisSettings:
|
|
"""Get Redis settings from app config."""
|
|
settings = get_settings()
|
|
return RedisSettings.from_dsn(settings.redis_url)
|
|
|
|
|
|
async def on_startup(ctx: dict[str, Any]) -> None:
|
|
"""Called when worker starts."""
|
|
logger.info("ARQ worker starting...")
|
|
# Register search providers (normally done by app startup)
|
|
try:
|
|
from app.core.db import get_session_factory
|
|
from app.plugins.builtins.unified_search.provider_registry import auto_register_providers
|
|
factory = get_session_factory()
|
|
async with factory() as db:
|
|
await auto_register_providers(db)
|
|
logger.info("Search providers registered for worker")
|
|
except Exception:
|
|
logger.warning("Failed to register search providers in worker", exc_info=True)
|
|
|
|
|
|
async def on_shutdown(ctx: dict[str, Any]) -> None:
|
|
"""Called when worker shuts down."""
|
|
logger.info("ARQ worker shutting down...")
|
|
|
|
|
|
# Import job functions directly so ARQ registers them by __name__
|
|
from app.plugins.builtins.unified_search.jobs import (
|
|
index_mails,
|
|
index_file,
|
|
index_contact,
|
|
index_event,
|
|
reindex,
|
|
embedding_batch,
|
|
)
|
|
from app.plugins.builtins.ai_proactive.jobs import deep_analysis
|
|
from app.plugins.builtins.automation.scheduler import scheduler_tick
|
|
from app.plugins.builtins.automation.workflow_timeout import check_workflow_timeouts
|
|
from app.plugins.builtins.automation.agent_runner import run_agent
|
|
from app.plugins.builtins.automation.execution_engine import run_automation
|
|
|
|
|
|
class WorkerSettings:
|
|
"""ARQ worker settings."""
|
|
functions = [
|
|
index_mails,
|
|
index_file,
|
|
index_contact,
|
|
index_event,
|
|
reindex,
|
|
embedding_batch,
|
|
deep_analysis,
|
|
scheduler_tick,
|
|
check_workflow_timeouts,
|
|
run_agent,
|
|
run_automation,
|
|
]
|
|
redis_settings = _get_redis_settings()
|
|
on_startup = on_startup
|
|
on_shutdown = on_shutdown
|
|
max_jobs = 10
|
|
job_timeout = 300
|
|
queue_name = "arq:queue"
|
|
cron_jobs = [
|
|
cron(scheduler_tick, second={0, 30}),
|
|
cron(check_workflow_timeouts, minute={0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55}),
|
|
]
|