@@ -64,7 +64,7 @@ class EventQueueGenericOutboxHandler extends EventQueueBaseClass {
6464 }
6565 } else {
6666 for ( const actionName in genericClusterEvents ) {
67- const reg = new cds . Request ( {
67+ const req = new cds . Request ( {
6868 event : EVENT_QUEUE_ACTIONS . CLUSTER ,
6969 user : this . context . user ,
7070 eventQueue : {
@@ -77,14 +77,14 @@ class EventQueueGenericOutboxHandler extends EventQueueBaseClass {
7777 this . #clusterByDataProperty( actionName , genericClusterEvents [ actionName ] , propertyName , cb ) ,
7878 } ,
7979 } ) ;
80- const clusterResult = await this . __srvUnboxed . tx ( this . context ) . send ( reg ) ;
80+ const clusterResult = await this . __srvUnboxed . tx ( this . context ) . send ( req ) ;
8181 if ( this . #validateCluster( clusterResult ) ) {
8282 Object . assign ( clusterMap , clusterResult ) ;
8383 } else {
8484 this . logger . error (
8585 "cluster result of handler is not valid. Check the documentation for the expected structure. Continuing without clustering!" ,
8686 {
87- handler : reg . event ,
87+ handler : req . event ,
8888 clusterResult : JSON . stringify ( clusterResult ) ,
8989 }
9090 ) ;
@@ -95,7 +95,7 @@ class EventQueueGenericOutboxHandler extends EventQueueBaseClass {
9595 }
9696
9797 for ( const actionName in specificClusterEvents ) {
98- const reg = new cds . Request ( {
98+ const req = new cds . Request ( {
9999 event : `${ EVENT_QUEUE_ACTIONS . CLUSTER } .${ actionName } ` ,
100100 user : this . context . user ,
101101 eventQueue : {
@@ -108,14 +108,14 @@ class EventQueueGenericOutboxHandler extends EventQueueBaseClass {
108108 this . #clusterByDataProperty( actionName , specificClusterEvents [ actionName ] , propertyName , cb ) ,
109109 } ,
110110 } ) ;
111- const clusterResult = await this . __srvUnboxed . tx ( this . context ) . send ( reg ) ;
111+ const clusterResult = await this . __srvUnboxed . tx ( this . context ) . send ( req ) ;
112112 if ( this . #validateCluster( clusterResult ) ) {
113113 Object . assign ( clusterMap , clusterResult ) ;
114114 } else {
115115 this . logger . error (
116116 "cluster result of handler is not valid. Check the documentation for the expected structure. Continuing without clustering!" ,
117117 {
118- handler : reg . event ,
118+ handler : req . event ,
119119 clusterResult : JSON . stringify ( clusterResult ) ,
120120 }
121121 ) ;
@@ -267,12 +267,12 @@ class EventQueueGenericOutboxHandler extends EventQueueBaseClass {
267267 return payload ;
268268 }
269269
270- const { reg , userId } = this . #buildDispatchData( this . context , payload , {
270+ const { req , userId } = this . #buildDispatchData( payload , {
271271 queueEntries : [ queueEntry ] ,
272272 } ) ;
273- reg . event = handlerName ;
274- await this . #setContextUser( this . context , userId , reg ) ;
275- const data = await this . __srvUnboxed . tx ( this . context ) . send ( reg ) ;
273+ req . event = handlerName ;
274+ await this . #setContextUser( this . context , userId , req ) ;
275+ const data = await this . __srvUnboxed . tx ( this . context ) . send ( req ) ;
276276 if ( data ) {
277277 payload . data = data ;
278278 return payload ;
@@ -288,12 +288,12 @@ class EventQueueGenericOutboxHandler extends EventQueueBaseClass {
288288 return await super . hookForExceededEvents ( exceededEvent ) ;
289289 }
290290
291- const { reg , userId } = this . #buildDispatchData( this . context , exceededEvent . payload , {
291+ const { req , userId } = this . #buildDispatchData( exceededEvent . payload , {
292292 queueEntries : [ exceededEvent ] ,
293293 } ) ;
294- await this . #setContextUser( this . context , userId , reg ) ;
295- reg . event = handlerName ;
296- await this . __srvUnboxed . tx ( this . context ) . send ( reg ) ;
294+ await this . #setContextUser( this . context , userId , req ) ;
295+ req . event = handlerName ;
296+ await this . __srvUnboxed . tx ( this . context ) . send ( req ) ;
297297 }
298298
299299 // NOTE: Currently not exposed to CAP service; we wait for a valid use case
@@ -326,40 +326,47 @@ class EventQueueGenericOutboxHandler extends EventQueueBaseClass {
326326
327327 async processPeriodicEvent ( processContext , key , queueEntry ) {
328328 const { actionName } = config . normalizeSubType ( this . eventType , this . eventSubType ) ;
329- const reg = new cds . Event ( { event : actionName , eventQueue : { processor : this , key, queueEntries : [ queueEntry ] } } ) ;
330- await this . #setContextUser( processContext , config . userId , reg ) ;
331- await this . __srvUnboxed . tx ( processContext ) . emit ( reg ) ;
329+ const req = new cds . Event ( { event : actionName , eventQueue : { processor : this , key, queueEntries : [ queueEntry ] } } ) ;
330+ await this . #setContextUser( processContext , config . userId , req ) ;
331+ await this . __srvUnboxed . tx ( processContext ) . emit ( req ) ;
332332 }
333333
334- #buildDispatchData( context , payload , { key, queueEntries } = { } ) {
334+ #buildDispatchData( payload , { key, queueEntries } = { } ) {
335335 const { useEventQueueUser } = this . eventConfig ;
336336 const userId = useEventQueueUser ? config . userId : payload . contextUser ;
337- const reg = payload . _fromSend ? new cds . Request ( payload ) : new cds . Event ( payload ) ;
337+ const req = payload . _fromSend ? new cds . Request ( payload ) : new cds . Event ( payload ) ;
338338 const invocationFn = payload . _fromSend ? "send" : "emit" ;
339- delete reg . _fromSend ;
340- delete reg . contextUser ;
341- reg . eventQueue = { processor : this , key, queueEntries, payload } ;
342- return { reg, userId, invocationFn } ;
339+ delete req . _fromSend ;
340+ delete req . contextUser ;
341+ req . eventQueue = { processor : this , key, queueEntries, payload } ;
342+
343+ if ( this . eventConfig . propagateContextProperties ?. length && this . transactionMode === "isolated" && cds . context ) {
344+ for ( const prop of this . eventConfig . propagateContextProperties ) {
345+ req [ prop ] && ( cds . context [ prop ] = req [ prop ] ) ;
346+ }
347+ }
348+
349+ return { req, userId, invocationFn } ;
343350 }
344351
345- async #setContextUser( context , userId , reg ) {
352+ async #setContextUser( context , userId , req ) {
346353 const authInfo = await common . getAuthContext ( context . tenant ) ;
347354 context . user = new cds . User . Privileged ( {
348355 id : userId ,
349356 authInfo,
350357 tokenInfo : authInfo ?. token ,
351358 } ) ;
352- if ( reg ) {
353- reg . user = context . user ;
359+ if ( req ) {
360+ req . user = context . user ;
354361 }
355362 }
356363
357364 async processEvent ( processContext , key , queueEntries , payload ) {
358365 let statusTuple ;
359- const { userId, invocationFn, reg } = this . #buildDispatchData( processContext , payload , { key, queueEntries } ) ;
366+ const { userId, invocationFn, req } = this . #buildDispatchData( payload , { key, queueEntries } ) ;
360367 try {
361- await this . #setContextUser( processContext , userId , reg ) ;
362- const result = await this . __srvUnboxed . tx ( processContext ) [ invocationFn ] ( reg ) ;
368+ await this . #setContextUser( processContext , userId , req ) ;
369+ const result = await this . __srvUnboxed . tx ( processContext ) [ invocationFn ] ( req ) ;
363370 statusTuple = this . #determineResultStatus( result , queueEntries ) ;
364371 } catch ( err ) {
365372 this . logger . error ( "error processing outboxed service call" , err , {
@@ -374,7 +381,7 @@ class EventQueueGenericOutboxHandler extends EventQueueBaseClass {
374381 ] ) ;
375382 }
376383
377- await this . #publishFollowupEvents( processContext , reg , statusTuple ) ;
384+ await this . #publishFollowupEvents( processContext , req , statusTuple ) ;
378385 return statusTuple ;
379386 }
380387
0 commit comments