@amag-ch/sap_cap_common_jobs

3.0.1 • Public • Published

sap_cap_common_jobs

npm version npm downloads

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

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i @amag-ch/sap_cap_common_jobs

Weekly Downloads

22

Version

3.0.1

License

MIT

Unpacked Size

8.25 kB

Total Files

7

Last publish

Collaborators

  • thju-amag-ch
  • integration-amag-ch