Skip to content

Commit

Permalink
fix: handle delete non-api source from prod (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saelmala authored Nov 14, 2024
1 parent a7b55e4 commit e832afb
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 96 deletions.
4 changes: 2 additions & 2 deletions src/api/ateliereLive/pipelines/streams/streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
44 changes: 22 additions & 22 deletions src/api/manager/productions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ function deleteMonitoring(db: Db, productionId: string) {
export async function getProductionPipelineSourceAlignment(
productionId: string,
pipelineId: string,
sourceId: number,
sourceIngestName: string
ingestSourceName: string,
ingestName: string
) {
const production = await getProduction(productionId);

Expand All @@ -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 =
Expand All @@ -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();
Expand All @@ -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: {
Expand All @@ -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
}
]
}
Expand All @@ -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);

Expand All @@ -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 =
Expand All @@ -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();
Expand All @@ -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: {
Expand All @@ -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
}
]
}
Expand Down
12 changes: 6 additions & 6 deletions src/api/manager/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function GET(
? await getProductionPipelineSourceAlignment(
params.id,
params.pipeline_id,
sourceId,
params.ingest_source_name,
params.ingest_name
)
: 0;
Expand All @@ -50,7 +50,7 @@ export async function GET(
? await getProductionSourceLatency(
params.id,
params.pipeline_id,
sourceId,
params.ingest_source_name,
params.ingest_name
)
: 0;
Expand Down Expand Up @@ -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
);

Expand Down
59 changes: 21 additions & 38 deletions src/app/production/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -133,7 +133,8 @@ export default function ProductionConfiguration({ params }: PageProps) {
const [firstEmptySlot] = useGetFirstEmptySlot();

const [updateStream, loading] = useUpdateStream();
const [getIngestSourceId, ingestSourceIdLoading] = useIngestSourceId();

const [getIngestSourceId] = useIngestSourceId();

const putProductionPipelineSourceAlignmentAndLatency =
usePutProductionPipelineSourceAlignmentAndLatency();
Expand Down Expand Up @@ -352,7 +353,6 @@ export default function ProductionConfiguration({ params }: PageProps) {

const handleSetPipelineSourceSettings = async (
source: ISource,
sourceId: number,
data: {
pipeline_uuid: string;
stream_uuid: string;
Expand Down Expand Up @@ -388,10 +388,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;
Expand All @@ -412,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;
Expand Down Expand Up @@ -594,24 +598,20 @@ export default function ProductionConfiguration({ params }: PageProps) {
source: SourceWithId
): Promise<Production> => {
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
Expand Down Expand Up @@ -761,12 +761,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
}
Expand Down Expand Up @@ -1003,18 +1000,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
);

Expand Down Expand Up @@ -1180,12 +1169,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,
Expand All @@ -1194,7 +1177,7 @@ export default function ProductionConfiguration({ params }: PageProps) {
input_slot: source.input_slot
},
productionSetup,
ingestSourceId,
ingestSource?.ingest_source_name,
ingestSource?.ingest_name
);
if (!updatedSetup) return;
Expand Down
18 changes: 2 additions & 16 deletions src/components/modal/ConfigureAlignmentLatencyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type ConfigureAlignmentModalProps = {
onAbort: () => void;
onConfirm: (
source: ISource,
sourceId: number,
data: {
pipeline_uuid: string;
stream_uuid: string;
Expand Down Expand Up @@ -67,7 +66,6 @@ export function ConfigureAlignmentLatencyModal({
const [alignments, setAlignments] = useState<Settings>({});
const [latencies, setLatencies] = useState<Settings>({});
const previousLatenciesRef = useRef<Settings>({});
const [sourceId, setSourceId] = useState<number>(0);
const [showRestartStreamModal, setShowRestartStreamModal] =
useState<boolean>(false);
const [inputErrors, setInputErrors] = useState<Record<string, boolean>>({});
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}
Expand All @@ -250,7 +236,7 @@ export function ConfigureAlignmentLatencyModal({
setInputErrors({});
});

onConfirm(source, sourceId, alignmentData);
onConfirm(source, alignmentData);
handleCloseModal();
}
};
Expand Down
1 change: 0 additions & 1 deletion src/components/sourceCard/SourceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type SourceCardProps = {
onSelectingText: (bool: boolean) => void;
onConfirm: (
source: ISource,
sourceId: number,
data: {
pipeline_uuid: string;
stream_uuid: string;
Expand Down
Loading

0 comments on commit e832afb

Please sign in to comment.