Skip to main content

kaizen/sync/
export_batch.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2//! Redacted batch payload shared by Kaizen sync POST and pluggable exporter fan-out.
3
4use crate::sync::outbound::EventsBatchBody;
5use crate::sync::smart::{RepoSnapshotsBatchBody, ToolSpansBatchBody, WorkspaceFactsBatchBody};
6
7/// Same JSON bodies as the ingest API; used for both primary sync and optional exporters.
8#[derive(Debug, Clone)]
9pub enum IngestExportBatch {
10    Events(EventsBatchBody),
11    ToolSpans(ToolSpansBatchBody),
12    RepoSnapshots(RepoSnapshotsBatchBody),
13    WorkspaceFacts(WorkspaceFactsBatchBody),
14}
15
16impl IngestExportBatch {
17    pub fn kind_name(&self) -> &'static str {
18        match self {
19            IngestExportBatch::Events(_) => "events",
20            IngestExportBatch::ToolSpans(_) => "tool_spans",
21            IngestExportBatch::RepoSnapshots(_) => "repo_snapshots",
22            IngestExportBatch::WorkspaceFacts(_) => "workspace_facts",
23        }
24    }
25
26    pub fn item_count(&self) -> usize {
27        match self {
28            IngestExportBatch::Events(b) => b.events.len(),
29            IngestExportBatch::ToolSpans(b) => b.spans.len(),
30            IngestExportBatch::RepoSnapshots(b) => b.snapshots.len(),
31            IngestExportBatch::WorkspaceFacts(b) => b.facts.len(),
32        }
33    }
34}