sandbox/ivideon/puml/insight/task_generator/data_flow.puml
2026-09-25 15:48:21 +03:00

81 lines
No EOL
2.9 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@startuml insight_quota_flow
skinparam sequenceMessageAlign center
autonumber
participant "event_server" as EventServer
participant "task_generator\nAPI" as ITG_API
database "DB" as Mongo
queue "NSQ" as NSQ
participant "task_processor" as TaskProcessor
EventServer -> ITG_API : На API /events\nприсылается JSON события.\n\nЛевее представлены важные поля для сервиса
note left
<code>
{
"id": "8cc8BDfLSZcQhGnx.55",
"user": "100000608486",
"type": "motion/started",
"name": "Motion",
"description": "Motion",
"time": 1790251591.802,
"source_type": "camera",
"source_id": "100-E87hD7H7dN08Ve3zuoibRz:11796480",
"device_type": "camera",
"device_id": "100-E87hD7H7dN08Ve3zuoibRz:11796480",
"preview": "https://some_pic.jpeg",
"clip": "https://some_clip.mp4",
"clip_duration": 10,
"value": null,
"status": "new",
"delivered": true,
"data": null,
"chain_id": "rqa5XhYU9X9sqm3i",
"updated_at": 1790251597.4111845,
"alert_status": null,
"allowed_next_alert_statuses": [
"suspicious",
"alert",
"false_positive"
],
"priority": null,
"marker": false,
"_id": "8cc8BDfLSZcQhGnx.55"
}
</code>
end note
ITG_API -> ITG_API : Из JSON'а формируется\nмодель ""IncomingEvent""
note left
Тут после формирования модели надо:
1. Сходить в БД
2. Найти сценарии Insight пользователей по полю ""user""
2.1 Надо смотреть в API ""InsightScenario""
2.2 У сценария есть поле ""trigger"", которое выглядит примерно так:
<code>
Scenario.trigger.event_types = ['motion']
</code>
которое и надо метчить с полем ""type"" события
end note
ITG_API -> Mongo : Забираем Insight сценарии пользователя\n""user""\nи подходящим ""event_type""'ом\n\nСм запрос левее
note left
<code>
db.scenarios.find({
"trigger.type": "event",
"trigger.event_types": "motion/started",
"owner_id": "100000608486",
"enabled": true,
"deleted": { $ne: true }
})
</code>
end note
Mongo --> ITG_API : ""Optional[List]"" сценарий пользователя
alt Запрос пришел с пустым списком
ITG_API --> EventServer : Возврат пустого списка (т.к. таски никакие не созданы)
else Список сценариев не пуст
ITG_API -> ITG_API : Создаем список\n""tasks""\nКуда будем писать созданные таски
loop Для каждого сценария
ITG_API -> ITG_API : Создаем объект\n""Task""\n
ITG_API -> ITG_API : Добавляем их `id` в список ""tasks""
end
ITG_API --> EventServer : Возврат список созданных тасок
end