cancel
Showing results for 
Search instead for 
Did you mean: 

Cron Job in multi tenant Rest/Cap application

krishnan-jr
Explorer
0 Kudos

Hi experts,

I am working on multi tenant application in which i want to set up a cron job which syncs invoice data from an S4 system through destination. I want this job to run on all tenants on every day on a particular time without needing to trigger the action. Can someone suggest an approach i can take to find a solution

Thanks.

Accepted Solutions (0)

Answers (1)

Answers (1)

david_kunz2
Advisor
Advisor

Hi krishnan.jr ,

You can either use the job scheduler service (this will trigger external HTTP requests against the endpoint), or you can use `cds.spawn` to schedule async jobs.
https://cap.cloud.sap/docs/node.js/transactions#cds-spawn

Best regards,
David

gregorw
Active Contributor
0 Kudos

Hi David,

srv.tx ({ tenant?, user?, … }) → txsrv will work to execute DB requests for the specific tenant. But how does the tenant specific destination lookup work when the job is triggered in the CAP service of the provider account? I think to lookup the S/4HANA destination that is maintained in the subscriber subaccount also the job needs to be started via the approuter URL of the thenant. Or is that something that is controlled by the selectionStrategy that is documented in Destinations and Multitenancy?

Best Regards
Gregor

david_kunz2
Advisor
Advisor
0 Kudos

Hi gregorw ,

That's a good point. For tenant-specific destination lookup a JWT token is needed, which you won't have when looping over the tenants. Therefore, you need to trigger a tenant-specific HTTP request from outside.
Best regards,
David