-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to run background jobs which require Principal Propagation to SAP Backend? #58
Comments
Hi @codeyogi911,
cds.spawn ({ tenant:'t0', every: 1000 /* ms */ }, async (tx) => {
const mails = await SELECT.from('Outbox')
await MailServer.send(mails)
await DELETE.from('Outbox').where (`ID in ${mails.map(m => m.ID)}`)
}) |
@alperdedeoglu I am aware about how to use |
@codeyogi911 What kind of SAP Backend are we talking about? Can you explain the exact use case you have? |
I have an SAP Onprem system connected to our multi-tenant app. We are running in the background a |
Where exactly do you get your JWT from? Do you mean the XSUAA? By Backend API do you mean CAP API or S/4 API? |
Right now as a workaround i get the |
And are you using Cloud SDK or something to connect to the backend? Or have you defined a destination? How do you call the on-premise backend? Which library do you use? |
I have my function to create sales order defined like: async function createSalesOrder(orderData) {
LOGGER.info("Creating sales order: ", cds.context.user)
const salesSrv = await cds.connect.to("API_SALES_ORDER_SRV", {
destinationOptions: {
jwt: cds.context.user.tokenInfo.getTokenValue(),
}
})
const result = await salesSrv.create("A_SalesOrder").entries(orderData)
LOGGER.info("Sales order created", result.SalesOrder)
return result
} earlier i had it defined like: async function createSalesOrder(orderData) {
let salesSrv
if (cds.context.isPrivilegedSpawn) {
const subDomain = await getTenantSubdomain(cds.context.tenant)
LOGGER.info("Subdomain for tenant", subDomain)
LOGGER.info("Creating sales order for tenant using basic authentication", cds.context.tenant)
salesSrv = await cds.connect.to("API_SALES_ORDER_SRV", {
credentials: {
destination: "onpremise-basic",
path: "/sap/opu/odata/sap/API_SALES_ORDER_SRV",
},
destinationOptions: {
selectionStrategy: "alwaysSubscriber",
iss: `https://${subDomain}.authentication.eu10.hana.ondemand.com/oauth/token`,
useCache: true,
},
})
} else {
salesSrv = await cds.connect.to("API_SALES_ORDER_SRV")
}
const result = await salesSrv.create("A_SalesOrder").entries(orderData)
LOGGER.info("Sales order created", result.SalesOrder)
return result
} so this stopped working after the upgrading to CDS8, it somehow now gives me 401 when using "API_SALES_ORDER_SRV": {
"kind": "odata-v2",
"model": "srv/external/API_SALES_ORDER_SRV",
"csrf": true,
"csrfInBatch": true,
"[production]": {
"credentials": {
"destination": "onpremise",
"path": "/sap/opu/odata/sap/API_SALES_ORDER_SRV"
},
"destinationOptions": {
"selectionStrategy": "alwaysSubscriber",
"useCache": false
}
}
}, |
Ok got it, can you just give the |
Hi @codeyogi911, did that work for you? |
I have a use case where the background job needs to access the backend system via
destinations
in a multi tenant app. How can i achieve this? Basically i want to run a background job with atechnical user
The text was updated successfully, but these errors were encountered: