6e7e39d101
Critical fixes:
- Event Bus → Workflow auto-trigger: wildcard subscription starts workflows on matching events
- Kommunikation routes: require_permission on all 30+ endpoints (comm:read/write/delete/manage)
- Permissions routes: require_permission('permissions:admin') on all management endpoints
- CompanySearchProvider registered in auto_register_providers()
Medium fixes:
- system_notif events: 10 event_bus.publish() calls added (lead.created, contact.created/updated,
task.created/overdue, mail.received, user.created, workflow.completed, notification.created, backup.*)
- Cron jobs: backup_check (daily), search_index_check (daily), workflow_timeout (5min) registered
- AI tool permission: call_crm_api now requires 'ai:write' permission
- New file: automation/jobs.py with backup_check and search_index_check functions
62 lines
2.3 KiB
Python
62 lines
2.3 KiB
Python
"""ARQ reminder job for due tasks — sends notifications for overdue/due tasks."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from datetime import datetime, timezone
|
|
|
|
from app.core.db import get_session_factory
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def tasks_due_reminder(ctx: dict) -> None:
|
|
"""Check for due tasks and send notifications to assigned users.
|
|
|
|
Runs daily at 8:00 via cron. Finds all non-done tasks with due_date <= now
|
|
and creates a notification for the assigned user.
|
|
"""
|
|
from app.plugins.builtins.tasks.services import get_due_tasks
|
|
from app.models.tenant import Tenant
|
|
from app.core.notifications import create_notification
|
|
from sqlalchemy import select
|
|
|
|
factory = get_session_factory()
|
|
async with factory() as db:
|
|
result = await db.execute(select(Tenant))
|
|
tenants = result.scalars().all()
|
|
|
|
total_notified = 0
|
|
for tenant in tenants:
|
|
try:
|
|
due_tasks = await get_due_tasks(db, tenant.id)
|
|
for task in due_tasks:
|
|
if not task.get("assigned_to"):
|
|
continue
|
|
await create_notification(
|
|
db,
|
|
user_id=task["assigned_to"],
|
|
tenant_id=str(tenant.id),
|
|
type="task_due",
|
|
title=f"Task due: {task['title']}",
|
|
body=f"Task '{task['title']}' is due. Priority: {task['priority']}",
|
|
data={"task_id": task["id"], "due_date": task.get("due_date")},
|
|
)
|
|
total_notified += 1
|
|
|
|
# Publish task.overdue event
|
|
from app.core.event_bus import get_event_bus
|
|
event_bus = get_event_bus()
|
|
await event_bus.publish('task.overdue', {
|
|
'event_id': task['id'],
|
|
'tenant_id': str(tenant.id),
|
|
'user_id': str(task.get('assigned_to', '')),
|
|
'title': task['title'],
|
|
})
|
|
except Exception:
|
|
logger.warning(f"Failed to process due tasks for tenant {tenant.id}", exc_info=True)
|
|
|
|
if total_notified > 0:
|
|
logger.info(f"Tasks reminder: sent {total_notified} notifications")
|
|
await db.commit()
|