@amag-ch/sap_cap_common_jobs
v3.0.1
Published
Wrapper for cds.spawn with additional functionality
Downloads
182
Readme
sap_cap_common_jobs
Wrapper for cds.spawn with additional functionality
Table of Contents
Features
- Block jobs to avoid parallel processing
- Set context id to job for better monitoring
- Background jobs
Installing
Using npm:
$ npm install @amag-ch/sap_cap_common_jobs
Using yarn:
$ yarn add @amag-ch/sap_cap_common_jobs
Implementation
const jobs = require('@amag-ch/sap_cap_common_jobs')
jobs.spawn({ every: 1000, blockingId: 'a-blocking-id' }, async () => {
// do something
})
A background job need two processing functions, called selector and executer, which must be given at construction. The job calls the selector and calls afterthen the executer with the selected entries. The job finish, if the selector didn't return any entries. Therefore it's needed to start the job again after the source of the selector have changed.
The job automaticly starts the first time after the cds server is up and running.
If the selector or executer produces an error, the jobs stopps and reschedule after a defined delay (default: 60000)
The name or the delay could be changed in the third argument of the constructor.
const { BackgroundJob } = require('@amag-ch/sap_cap_common_jobs')
const job = new BackgroundJob(
async () => db.read('Table').limit(10).forUpdate(),
async (entries) => console.log(entries)
)
job.start() // only possible, if current cds.context is set