From f3361d64ffa5933663e68a10e8e1af5a21ec72b5 Mon Sep 17 00:00:00 2001 From: Saelmala Date: Thu, 14 Nov 2024 15:43:16 +0100 Subject: [PATCH 1/2] fix: handle delete non-api source from prod --- .../ateliereLive/pipelines/streams/streams.ts | 4 +- src/api/manager/productions.ts | 44 ++++++++-------- src/api/manager/workflow.ts | 12 ++--- .../[ingest_source_name]/route.ts | 8 +-- src/app/production/[id]/page.tsx | 52 ++++++------------- src/hooks/items/removeSetupItem.ts | 8 +-- src/interfaces/pipeline.ts | 4 +- 7 files changed, 55 insertions(+), 77 deletions(-) diff --git a/src/api/ateliereLive/pipelines/streams/streams.ts b/src/api/ateliereLive/pipelines/streams/streams.ts index eeae1d68..879c1760 100644 --- a/src/api/ateliereLive/pipelines/streams/streams.ts +++ b/src/api/ateliereLive/pipelines/streams/streams.ts @@ -109,8 +109,8 @@ export async function createStream( const pipelineSource = pipeline.sources?.find( (s) => - s.source_id === sourceId && - s.settings.ingest_name === source.ingest_name + s.ingest_source_name === source.ingest_source_name && + s.ingest_name === source.ingest_name ); const stream: PipelineStreamSettings = { diff --git a/src/api/manager/productions.ts b/src/api/manager/productions.ts index 327a42b9..1d923a61 100644 --- a/src/api/manager/productions.ts +++ b/src/api/manager/productions.ts @@ -104,8 +104,8 @@ function deleteMonitoring(db: Db, productionId: string) { export async function getProductionPipelineSourceAlignment( productionId: string, pipelineId: string, - sourceId: number, - sourceIngestName: string + ingestName: string, + ingestSourceName: string ) { const production = await getProduction(productionId); @@ -120,8 +120,8 @@ export async function getProductionPipelineSourceAlignment( const source = pipeline?.sources?.find( (source) => - String(source.source_id) === String(sourceId) && - source.settings.ingest_name === sourceIngestName + source.ingest_name === ingestName && + source.ingest_source_name === ingestSourceName ); const alignment = @@ -135,8 +135,8 @@ export async function getProductionPipelineSourceAlignment( export async function setProductionPipelineSourceAlignment( productionId: string, pipelineId: string, - sourceId: number, - sourceIngestName: string, + ingestName: string, + ingestSourceName: string, alignment_ms: number ) { const db = await getDatabase(); @@ -146,9 +146,9 @@ export async function setProductionPipelineSourceAlignment( { _id: new ObjectId(productionId), 'production_settings.pipelines.pipeline_id': pipelineId, - 'production_settings.pipelines.sources.source_id': sourceId, - 'production_settings.pipelines.sources.settings.ingest_name': - sourceIngestName + 'production_settings.pipelines.sources.ingest_name': ingestName, + 'production_settings.pipelines.sources.ingest_source_name': + ingestSourceName }, { $set: { @@ -160,8 +160,8 @@ export async function setProductionPipelineSourceAlignment( arrayFilters: [ { 'p.pipeline_id': pipelineId }, { - 's.source_id': sourceId, - 's.settings.ingest_name': sourceIngestName + 's.ingest_name': ingestName, + 's.ingest_source_name': ingestSourceName } ] } @@ -182,8 +182,8 @@ export async function setProductionPipelineSourceAlignment( export async function getProductionSourceLatency( productionId: string, pipelineId: string, - sourceId: number, - sourceIngestName: string + ingestSourceName: string, + ingestName: string ) { const production = await getProduction(productionId); @@ -198,8 +198,8 @@ export async function getProductionSourceLatency( const source = pipeline?.sources?.find( (source) => - String(source.source_id) === String(sourceId) && - source.settings.ingest_name === sourceIngestName + source.ingest_name === ingestName && + source.ingest_source_name === ingestSourceName ); const latency = @@ -212,8 +212,8 @@ export async function getProductionSourceLatency( export async function setProductionPipelineSourceLatency( productionId: string, pipelineId: string, - sourceId: number, - sourceIngestName: string, + ingestName: string, + ingestSourceName: string, max_network_latency_ms: number ) { const db = await getDatabase(); @@ -223,9 +223,9 @@ export async function setProductionPipelineSourceLatency( { _id: new ObjectId(productionId), 'production_settings.pipelines.pipeline_id': pipelineId, - 'production_settings.pipelines.sources.source_id': sourceId, - 'production_settings.pipelines.sources.settings.ingest_name': - sourceIngestName + 'production_settings.pipelines.sources.ingest_name': ingestName, + 'production_settings.pipelines.sources.ingest_source_name': + ingestSourceName }, { $set: { @@ -237,8 +237,8 @@ export async function setProductionPipelineSourceLatency( arrayFilters: [ { 'p.pipeline_id': pipelineId }, { - 's.source_id': sourceId, - 's.settings.ingest_name': sourceIngestName + 's.ingest_name': ingestName, + 's.ingest_source_name': ingestSourceName } ] } diff --git a/src/api/manager/workflow.ts b/src/api/manager/workflow.ts index bddecf3e..5c4a77e3 100644 --- a/src/api/manager/workflow.ts +++ b/src/api/manager/workflow.ts @@ -128,8 +128,8 @@ async function connectIngestSources( const pipelineSource = pipeline.sources?.find( (s) => - s.source_id === sourceId && - s.settings.ingest_name === source.ingest_name + s.ingest_source_name === source.ingest_source_name && + s.ingest_name === source.ingest_name ); const stream: PipelineStreamSettings = { @@ -877,14 +877,14 @@ export async function startProduction( const currentSettings = pipeline.sources?.find( (s) => - s.source_id === sourceId && - s.settings.ingest_name === source.ingest_name + s.ingest_source_name === source.ingest_source_name && + s.ingest_name === source.ingest_name )?.settings; return { - source_id: sourceId || 0, + ingest_name: source.ingest_name, + ingest_source_name: source.ingest_source_name, settings: { - ingest_name: source.ingest_name, alignment_ms: currentSettings?.alignment_ms ?? pipeline.alignment_ms, max_network_latency_ms: diff --git a/src/app/api/manager/productions/[id]/[pipeline_id]/[ingest_name]/[ingest_source_name]/route.ts b/src/app/api/manager/productions/[id]/[pipeline_id]/[ingest_name]/[ingest_source_name]/route.ts index fda8a291..bb3585d5 100644 --- a/src/app/api/manager/productions/[id]/[pipeline_id]/[ingest_name]/[ingest_source_name]/route.ts +++ b/src/app/api/manager/productions/[id]/[pipeline_id]/[ingest_name]/[ingest_source_name]/route.ts @@ -40,7 +40,7 @@ export async function GET( ? await getProductionPipelineSourceAlignment( params.id, params.pipeline_id, - sourceId, + params.ingest_source_name, params.ingest_name ) : 0; @@ -50,7 +50,7 @@ export async function GET( ? await getProductionSourceLatency( params.id, params.pipeline_id, - sourceId, + params.ingest_source_name, params.ingest_name ) : 0; @@ -94,15 +94,15 @@ export async function PUT( const alignmentResult = await setProductionPipelineSourceAlignment( params.id, params.pipeline_id, - sourceId, params.ingest_name, + params.ingest_source_name, alignment ); const latencyResult = await setProductionPipelineSourceLatency( params.id, params.pipeline_id, - sourceId, params.ingest_name, + params.ingest_source_name, latency ); diff --git a/src/app/production/[id]/page.tsx b/src/app/production/[id]/page.tsx index 9072e9d3..ff51f3dc 100644 --- a/src/app/production/[id]/page.tsx +++ b/src/app/production/[id]/page.tsx @@ -20,7 +20,7 @@ import { usePutProduction, useReplaceProductionSourceStreamIds } from '../../../hooks/productions'; -import { Production, ProductionSettings } from '../../../interfaces/production'; +import { Production } from '../../../interfaces/production'; import { updateSetupItem } from '../../../hooks/items/updateSetupItem'; import { removeSetupItem } from '../../../hooks/items/removeSetupItem'; import { addSetupItem } from '../../../hooks/items/addSetupItem'; @@ -133,7 +133,6 @@ export default function ProductionConfiguration({ params }: PageProps) { const [firstEmptySlot] = useGetFirstEmptySlot(); const [updateStream, loading] = useUpdateStream(); - const [getIngestSourceId, ingestSourceIdLoading] = useIngestSourceId(); const putProductionPipelineSourceAlignmentAndLatency = usePutProductionPipelineSourceAlignmentAndLatency(); @@ -388,10 +387,10 @@ export default function ProductionConfiguration({ params }: PageProps) { pipelines: productionSetup.production_settings.pipelines.map( (pipeline) => { if (pipeline.pipeline_id === pipeline_uuid) { - pipeline.sources?.map((s) => { + pipeline.sources?.map(async (s) => { if ( - s.source_id === sourceId && - s.settings.ingest_name === source.ingest_name + s.ingest_source_name === source.ingest_source_name && + s.ingest_name === source.ingest_name ) { s.settings.alignment_ms = alignment; s.settings.max_network_latency_ms = latency; @@ -594,24 +593,20 @@ export default function ProductionConfiguration({ params }: PageProps) { source: SourceWithId ): Promise => { const updatedPipelines = await Promise.all( - productionSetup.production_settings.pipelines.map(async (pipeline) => { + productionSetup.production_settings.pipelines.map((pipeline) => { const newSource = { - source_id: await getIngestSourceId( - source.ingest_name, - source.ingest_source_name - ), + ingest_name: source.ingest_name, + ingest_source_name: source.ingest_source_name, settings: { - ingest_name: source.ingest_name, alignment_ms: pipeline.alignment_ms, max_network_latency_ms: pipeline.max_network_latency_ms } }; - const exists = pipeline.sources?.some( - (s) => - s.source_id === newSource.source_id && - s.settings.ingest_name === newSource.settings.ingest_name - ); + const exists = pipeline.sources?.some((s) => { + s.ingest_name === newSource.ingest_name && + s.ingest_source_name === newSource.ingest_source_name; + }); const updatedSources = exists ? pipeline.sources @@ -761,12 +756,9 @@ export default function ProductionConfiguration({ params }: PageProps) { } const newSource = { - source_id: await getIngestSourceId( - selectedSource.ingest_name, - selectedSource.ingest_source_name - ), + ingest_name: selectedSource.ingest_name, + ingest_source_name: selectedSource.ingest_source_name, settings: { - ingest_name: selectedSource.ingest_name, alignment_ms: pipeline.alignment_ms, max_network_latency_ms: pipeline.max_network_latency_ms } @@ -1003,18 +995,10 @@ export default function ProductionConfiguration({ params }: PageProps) { } } - const ingestSourceId = - ingestSource !== undefined - ? await getIngestSourceId( - ingestSource.ingest_name, - ingestSource.ingest_source_name - ) - : undefined; - const updatedSetup = removeSetupItem( selectedSourceRef, productionSetup, - ingestSourceId, + ingestSource?.ingest_source_name, ingestSource?.ingest_name ); @@ -1180,12 +1164,6 @@ export default function ProductionConfiguration({ params }: PageProps) { setSelectedSourceRef(source); setRemoveSourceModal(true); } else if (productionSetup) { - const ingestSourceId = ingestSource - ? await getIngestSourceId( - ingestSource.ingest_name, - ingestSource.ingest_source_name - ) - : undefined; const updatedSetup = removeSetupItem( { _id: source._id, @@ -1194,7 +1172,7 @@ export default function ProductionConfiguration({ params }: PageProps) { input_slot: source.input_slot }, productionSetup, - ingestSourceId, + ingestSource?.ingest_source_name, ingestSource?.ingest_name ); if (!updatedSetup) return; diff --git a/src/hooks/items/removeSetupItem.ts b/src/hooks/items/removeSetupItem.ts index 9e15006f..a490ab11 100644 --- a/src/hooks/items/removeSetupItem.ts +++ b/src/hooks/items/removeSetupItem.ts @@ -4,7 +4,7 @@ import { Production } from '../../interfaces/production'; export function removeSetupItem( source: SourceReference, productionSetup: Production, - ingestSourceId?: number, + ingestSourceName?: string, ingestName?: string ): Production | null { const tempItems = productionSetup.sources.filter( @@ -13,15 +13,15 @@ export function removeSetupItem( let updatedPipelines = productionSetup.production_settings.pipelines; - if (ingestSourceId !== undefined && ingestName !== undefined) { + if (ingestSourceName !== undefined && ingestName !== undefined) { updatedPipelines = productionSetup.production_settings.pipelines.map( (pipeline) => ({ ...pipeline, sources: pipeline.sources ? pipeline.sources.filter( (pipelineSource) => - pipelineSource.source_id !== ingestSourceId || - pipelineSource.settings.ingest_name !== ingestName + pipelineSource.ingest_source_name !== ingestSourceName || + pipelineSource.ingest_name !== ingestName ) : [] }) diff --git a/src/interfaces/pipeline.ts b/src/interfaces/pipeline.ts index 25f85bb4..f1c6bd46 100644 --- a/src/interfaces/pipeline.ts +++ b/src/interfaces/pipeline.ts @@ -10,9 +10,9 @@ export interface SrtOutput { } export interface PipelineSource { - source_id: number; + ingest_source_name: string; + ingest_name: string; settings: { - ingest_name: string; alignment_ms?: number; max_network_latency_ms?: number; }; From d3177e4d6a33422f190959200bab23c158cccd23 Mon Sep 17 00:00:00 2001 From: Saelmala Date: Thu, 14 Nov 2024 16:15:01 +0100 Subject: [PATCH 2/2] fix: errors with getting alignment --- src/api/manager/productions.ts | 4 ++-- src/app/production/[id]/page.tsx | 7 ++++++- .../modal/ConfigureAlignmentLatencyModal.tsx | 18 ++---------------- src/components/sourceCard/SourceCard.tsx | 1 - src/components/sourceCards/SourceCards.tsx | 1 - 5 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/api/manager/productions.ts b/src/api/manager/productions.ts index 1d923a61..22713bb2 100644 --- a/src/api/manager/productions.ts +++ b/src/api/manager/productions.ts @@ -104,8 +104,8 @@ function deleteMonitoring(db: Db, productionId: string) { export async function getProductionPipelineSourceAlignment( productionId: string, pipelineId: string, - ingestName: string, - ingestSourceName: string + ingestSourceName: string, + ingestName: string ) { const production = await getProduction(productionId); diff --git a/src/app/production/[id]/page.tsx b/src/app/production/[id]/page.tsx index ff51f3dc..93890279 100644 --- a/src/app/production/[id]/page.tsx +++ b/src/app/production/[id]/page.tsx @@ -134,6 +134,8 @@ export default function ProductionConfiguration({ params }: PageProps) { const [updateStream, loading] = useUpdateStream(); + const [getIngestSourceId] = useIngestSourceId(); + const putProductionPipelineSourceAlignmentAndLatency = usePutProductionPipelineSourceAlignmentAndLatency(); @@ -351,7 +353,6 @@ export default function ProductionConfiguration({ params }: PageProps) { const handleSetPipelineSourceSettings = async ( source: ISource, - sourceId: number, data: { pipeline_uuid: string; stream_uuid: string; @@ -411,6 +412,10 @@ export default function ProductionConfiguration({ params }: PageProps) { const sourceToDeleteFrom = productionSetup.sources.find((source) => source.stream_uuids?.includes(streamUuids[0]) ); + const sourceId = await getIngestSourceId( + source.ingest_name, + source.ingest_source_name + ); deleteStream(streamUuids, productionSetup, sourceId) .then(() => { delete sourceToDeleteFrom?.stream_uuids; diff --git a/src/components/modal/ConfigureAlignmentLatencyModal.tsx b/src/components/modal/ConfigureAlignmentLatencyModal.tsx index e65d508e..c0e9fc03 100644 --- a/src/components/modal/ConfigureAlignmentLatencyModal.tsx +++ b/src/components/modal/ConfigureAlignmentLatencyModal.tsx @@ -25,7 +25,6 @@ type ConfigureAlignmentModalProps = { onAbort: () => void; onConfirm: ( source: ISource, - sourceId: number, data: { pipeline_uuid: string; stream_uuid: string; @@ -67,7 +66,6 @@ export function ConfigureAlignmentLatencyModal({ const [alignments, setAlignments] = useState({}); const [latencies, setLatencies] = useState({}); const previousLatenciesRef = useRef({}); - const [sourceId, setSourceId] = useState(0); const [showRestartStreamModal, setShowRestartStreamModal] = useState(false); const [inputErrors, setInputErrors] = useState>({}); @@ -98,17 +96,6 @@ export function ConfigureAlignmentLatencyModal({ } }, [pipelinesAreSelected, latencies, alignments]); - useEffect(() => { - const fetchSourceId = async () => { - const id = await getIngestSourceId( - source.ingest_name, - source.ingest_source_name - ); - setSourceId(id); - }; - fetchSourceId(); - }, [source]); - useEffect(() => { const fetchStreams = async () => { try { @@ -221,14 +208,13 @@ export function ConfigureAlignmentLatencyModal({ if (shouldRestart) { onConfirm( source, - sourceId, alignmentData, true, sourceStreams.map((stream) => stream.stream_uuid) ); handleCloseModal(); } else { - onConfirm(source, sourceId, alignmentData); + onConfirm(source, alignmentData); if (!latenciesChanged) { handleCloseModal(); } @@ -250,7 +236,7 @@ export function ConfigureAlignmentLatencyModal({ setInputErrors({}); }); - onConfirm(source, sourceId, alignmentData); + onConfirm(source, alignmentData); handleCloseModal(); } }; diff --git a/src/components/sourceCard/SourceCard.tsx b/src/components/sourceCard/SourceCard.tsx index ae89ae73..15911c50 100644 --- a/src/components/sourceCard/SourceCard.tsx +++ b/src/components/sourceCard/SourceCard.tsx @@ -18,7 +18,6 @@ type SourceCardProps = { onSelectingText: (bool: boolean) => void; onConfirm: ( source: ISource, - sourceId: number, data: { pipeline_uuid: string; stream_uuid: string; diff --git a/src/components/sourceCards/SourceCards.tsx b/src/components/sourceCards/SourceCards.tsx index 922b5c2d..cd2901a3 100644 --- a/src/components/sourceCards/SourceCards.tsx +++ b/src/components/sourceCards/SourceCards.tsx @@ -25,7 +25,6 @@ export default function SourceCards({ onSourceRemoval: (source: SourceReference, ingestSource?: ISource) => void; onConfirm: ( source: ISource, - sourceId: number, data: { pipeline_uuid: string; stream_uuid: string;