@@ -48,6 +48,45 @@ type DockerWatcher = {
4848 } ;
4949} ;
5050
51+ type UpdateQueueBatchMetadata = {
52+ batchId : string ;
53+ queuePosition : number ;
54+ queueTotal : number ;
55+ } ;
56+
57+ function parsePositiveInteger ( value : unknown ) : number | undefined {
58+ if ( typeof value === 'number' ) {
59+ return Number . isSafeInteger ( value ) && value > 0 ? value : undefined ;
60+ }
61+ if ( typeof value !== 'string' || ! / ^ \d + $ / . test ( value ) ) {
62+ return undefined ;
63+ }
64+
65+ const parsed = Number . parseInt ( value , 10 ) ;
66+ return Number . isSafeInteger ( parsed ) && parsed > 0 ? parsed : undefined ;
67+ }
68+
69+ function parseUpdateQueueBatchMetadata ( body : unknown ) : UpdateQueueBatchMetadata | undefined {
70+ if ( ! body || typeof body !== 'object' ) {
71+ return undefined ;
72+ }
73+
74+ const candidate = body as Record < string , unknown > ;
75+ const batchId = typeof candidate . batchId === 'string' ? candidate . batchId . trim ( ) : '' ;
76+ const queuePosition = parsePositiveInteger ( candidate . queuePosition ) ;
77+ const queueTotal = parsePositiveInteger ( candidate . queueTotal ) ;
78+
79+ if ( ! batchId || ! queuePosition || ! queueTotal || queuePosition > queueTotal ) {
80+ return undefined ;
81+ }
82+
83+ return {
84+ batchId,
85+ queuePosition,
86+ queueTotal,
87+ } ;
88+ }
89+
5190function clearManualUpdateDetectionState ( id : string ) {
5291 const containerAfterTrigger = storeContainer . getContainer ( id ) ;
5392 if (
@@ -227,6 +266,7 @@ async function updateContainer(req: Request, res: Response) {
227266 }
228267
229268 const operationId = crypto . randomUUID ( ) ;
269+ const batchMetadata = parseUpdateQueueBatchMetadata ( req . body ) ;
230270 getContainerActionsCounter ( ) ?. inc ( { action : 'container-update' } ) ;
231271
232272 updateOperationStore . insertOperation ( {
@@ -235,6 +275,7 @@ async function updateContainer(req: Request, res: Response) {
235275 containerName : container . name ,
236276 status : 'queued' ,
237277 phase : 'queued' ,
278+ ...batchMetadata ,
238279 } ) ;
239280
240281 void ( async ( ) => {
0 commit comments