chore: Add bundled notification for segment membership updates
This commit is contained in:
@@ -34,6 +34,10 @@ async function processProjectSegments(projectId: string, projectName?: string):
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Process tracked segments with full membership computation (creates events)
|
// Process tracked segments with full membership computation (creates events)
|
||||||
|
let updatedSegmentCount = 0;
|
||||||
|
let totalAdded = 0;
|
||||||
|
let totalRemoved = 0;
|
||||||
|
|
||||||
if (trackedSegments.length > 0) {
|
if (trackedSegments.length > 0) {
|
||||||
for (const segment of trackedSegments) {
|
for (const segment of trackedSegments) {
|
||||||
try {
|
try {
|
||||||
@@ -45,22 +49,28 @@ async function processProjectSegments(projectId: string, projectName?: string):
|
|||||||
`[SEGMENT-COUNT-WORKER] Segment "${segment.name}": +${result.added} entries, -${result.removed} exits, ${result.total} total members`,
|
`[SEGMENT-COUNT-WORKER] Segment "${segment.name}": +${result.added} entries, -${result.removed} exits, ${result.total} total members`,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Notify about segment membership update only if there were actual changes
|
// Track segments with actual changes for bundled notification
|
||||||
if (projectName && (result.added > 0 || result.removed > 0)) {
|
if (result.added > 0 || result.removed > 0) {
|
||||||
await NtfyService.notifySegmentMembershipComputed(
|
updatedSegmentCount++;
|
||||||
segment.name,
|
totalAdded += result.added;
|
||||||
projectName,
|
totalRemoved += result.removed;
|
||||||
projectId,
|
|
||||||
result.total,
|
|
||||||
result.added,
|
|
||||||
result.removed,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
signale.error(`[SEGMENT-COUNT-WORKER] Failed to compute membership for segment ${segment.id}:`, error);
|
signale.error(`[SEGMENT-COUNT-WORKER] Failed to compute membership for segment ${segment.id}:`, error);
|
||||||
// Continue with other segments
|
// Continue with other segments
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send bundled notification if there were any changes
|
||||||
|
if (projectName && updatedSegmentCount > 0) {
|
||||||
|
await NtfyService.notifySegmentMembershipBundled(
|
||||||
|
projectName,
|
||||||
|
projectId,
|
||||||
|
updatedSegmentCount,
|
||||||
|
totalAdded,
|
||||||
|
totalRemoved,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process non-tracked segments with count-only update (lightweight)
|
// Process non-tracked segments with count-only update (lightweight)
|
||||||
|
|||||||
@@ -762,6 +762,32 @@ export class NtfyService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify about bundled segment membership updates - LOW priority
|
||||||
|
* Used when multiple segments are updated in a single processing cycle
|
||||||
|
*/
|
||||||
|
public static async notifySegmentMembershipBundled(
|
||||||
|
projectName: string,
|
||||||
|
projectId: string,
|
||||||
|
segmentCount: number,
|
||||||
|
totalAdded: number,
|
||||||
|
totalRemoved: number,
|
||||||
|
): Promise<void> {
|
||||||
|
const changes: string[] = [];
|
||||||
|
if (totalAdded > 0) changes.push(`+${totalAdded} added`);
|
||||||
|
if (totalRemoved > 0) changes.push(`-${totalRemoved} removed`);
|
||||||
|
|
||||||
|
const changesText = changes.length > 0 ? ` (${changes.join(', ')})` : '';
|
||||||
|
const message = `${segmentCount} segment${segmentCount > 1 ? 's' : ''} updated in project "${projectName}" (${projectId})${changesText}`;
|
||||||
|
|
||||||
|
await this.send({
|
||||||
|
title: 'Segment Memberships Updated',
|
||||||
|
message,
|
||||||
|
priority: NtfyPriority.LOW,
|
||||||
|
tags: [NtfyTag.CHART],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify about segment deleted - MIN priority
|
* Notify about segment deleted - MIN priority
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user