cancel
Showing results for 
Search instead for 
Did you mean: 

Async /Non Blocking Mode - SAP CAP

sandeepmalhotra
Participant
0 Kudos

Hello Everyone,

Kindly let me know the best way to handle task in background/non-blocking format which actually get triggers on the HTTP POST request instead of a scheduled job.

I have created a action named as publishNotification in SAP CAP.

Here are the details of the logic

In ‘On’ Event handler of an action , I am inserting entries in staging table.

And in ‘After’ Event I am calling async function named as triggerNotification which is wrapped in method setTimeout .I wrapped so that HTTO POST request ( for a action -- publishNotification ) is not blocked and implicit database commit happens . In this way I will have data in staging table

The logic of triggerNotification is to loop on staging table and triggers EMAIL and SMS and update the staging table with sent status.

I found that when no of recipient is more than 100, program failed to trigger EMAIL and SMS . It happens randomly . Even when I trigger multiple HTTP request simultaneously using multiple browser session , notification didn’t triggered for few users.

Kindly let me know , if there any better approach in SAP CAP to handle such situation.

Thanks

Sandeep

Accepted Solutions (1)

Accepted Solutions (1)

gregorw
Active Contributor

Have you tried: cds.spawn?

sandeepmalhotra
Participant
0 Kudos

Not yet . I will definitely try

seVladimirs
Active Contributor

+1 for cds.spawn, please see example https://youtu.be/WTOOse-Flj8?t=1688

sandeepmalhotra
Participant
0 Kudos

Thanks I tried to do cds.spawn in "after" hook method but unfortunately , my staging table is not having the data which is inserted in "on" hook method of the action .

If I do explicit commit using cds.tx in on even at the time of inserting data into staging table. I got below mentioned error

HANA commit Error

Sandeep

sandeepmalhotra
Participant
0 Kudos

gregor.wolf

Please let me know how to pass parameters in the function meant to be passed as parameter in cds.spawn
I tried

cds.spawn({ after: 1000 /* ms */ }, fnName(Parameters));

Got an error

Answers (1)

Answers (1)

SebastianEsch
Active Participant

An alternative to Gregors answer is using Messaging, you can start out with In-Process Messaging and later switch to SAP Event Mesh if required.

sandeepmalhotra
Participant
0 Kudos

Thanks Sebastian I will look into this alternative as well .