{"_id":"@amag-ch/cds-jobs","_rev":"3-cd680eae86ba21baf0ba6fc0600567b8","name":"@amag-ch/cds-jobs","dist-tags":{"latest":"3.3.0"},"versions":{"3.2.0":{"name":"@amag-ch/cds-jobs","version":"3.2.0","author":{"name":"AMAG Corporate Services AG"},"license":"MIT","_id":"@amag-ch/cds-jobs@3.2.0","maintainers":[{"name":"thju-amag-ch","email":"thomas.jurk@amag.ch"},{"name":"integration-amag-ch","email":"integration@amag.ch"}],"dist":{"shasum":"08e62ec453d0f3be23fe699d7ece596d02f5f920","tarball":"https://registry.npmjs.org/@amag-ch/cds-jobs/-/cds-jobs-3.2.0.tgz","fileCount":7,"integrity":"sha512-1txgX2fWHWPH0tpAb+xiB1wZfevXBc+5AOW+r4jllM1XfviXuDbUmICMznK8aHWZ3jgLuhhY+c9IxqqOS0ClMw==","signatures":[{"sig":"MEUCIQCiIIKNOgP5cYm022JCICOlJPiBAfEadhBgZiur2Q9kawIgajyngR4aOq+SMWVoBStLPJy3BEDy6VuQZF4/A9o47RY=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":7767},"main":"src/index.js","gitHead":"941bef9a962f0d2a7f34e618805aeb0e10a0b518","private":false,"_npmUser":{"name":"integration-amag-ch","email":"integration@amag.ch"},"repository":{"url":"gitlab.com:amag_web/sap/cap/common/cds-jobs.git","type":"git"},"_npmVersion":"10.9.2","description":"Wrapper for cds.spawn with additional functionality","directories":{},"_nodeVersion":"22.14.0","dependencies":{},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@sap/cds":">=7"},"peerDependencies":{"@sap/cds":">=7"},"_npmOperationalInternal":{"tmp":"tmp/cds-jobs_3.2.0_1742831659028_0.1257692047392207","host":"s3://npm-registry-packages-npm-production"}},"3.3.0":{"name":"@amag-ch/cds-jobs","version":"3.3.0","author":{"name":"AMAG Corporate Services AG"},"license":"MIT","_id":"@amag-ch/cds-jobs@3.3.0","maintainers":[{"name":"thju-amag-ch","email":"thomas.jurk@amag.ch"},{"name":"integration-amag-ch","email":"integration@amag.ch"}],"homepage":"https://gitlab.com/amag_web/sap/common/npm/cds-jobs#readme","bugs":{"url":"https://gitlab.com/amag_web/sap/common/npm/cds-jobs/issues"},"dist":{"shasum":"a279d697a60235a5d24401c3c2749f6cc8c7b277","tarball":"https://registry.npmjs.org/@amag-ch/cds-jobs/-/cds-jobs-3.3.0.tgz","fileCount":7,"integrity":"sha512-UgO1HNr99ObW0Dxn7660djM0Y2RhDUfrfgRQ5OFlDKxbBO+U9jQcjPSNFSftPiGtWlNjXqrW0yLCZrg6K77RMw==","signatures":[{"sig":"MEUCIQDGGUmMR0l2PrnL0HVsfhC4EW8cRfpFx0DN//Ur9ztqhAIgYfkHa57mFxqQsrcWd3Z8HQmXLsROsHVqYM9YAeuatpc=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":7849},"main":"src/index.js","type":"commonjs","gitHead":"cbf793a7bb51e1ad8ab452f3c52968d6e59f1349","private":false,"_npmUser":{"name":"GitLab CI/CD","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"gitlab","oidcConfigId":"oidc:b6b9e7a5-0cbd-4931-8811-e8044d05c663"}},"repository":{"url":"git+https://gitlab.com/amag_web/sap/common/npm/cds-jobs.git","type":"git"},"_npmVersion":"11.6.2","description":"Wrapper for cds.spawn with additional functionality","directories":{},"_nodeVersion":"24.13.0","dependencies":{},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@sap/cds":">=7"},"peerDependencies":{"@sap/cds":">=7"},"_npmOperationalInternal":{"tmp":"tmp/cds-jobs_3.3.0_1769539516578_0.6172776886733686","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2025-03-24T15:54:18.938Z","modified":"2026-06-10T21:30:09.425Z","3.2.0":"2025-03-24T15:54:19.284Z","3.3.0":"2026-01-27T18:45:16.743Z"},"bugs":{"url":"https://gitlab.com/amag_web/sap/common/npm/cds-jobs/issues"},"author":{"name":"AMAG Corporate Services AG"},"license":"MIT","homepage":"https://gitlab.com/amag_web/sap/common/npm/cds-jobs#readme","repository":{"url":"git+https://gitlab.com/amag_web/sap/common/npm/cds-jobs.git","type":"git"},"description":"Wrapper for cds.spawn with additional functionality","maintainers":[{"email":"integration@amag.ch","name":"integration-amag-ch"}],"readme":"# sap_cap_common_jobs\n\n[![npm version](https://img.shields.io/npm/v/@amag-ch/cds-jobs?style=flat-square)](https://www.npmjs.com/package/@amag-ch/cds-jobs)\n[![npm downloads](https://img.shields.io/npm/dm/@amag-ch/cds-jobs.svg?style=flat-square)](https://npm-stat.com/charts.html?package=@amag-ch/cds-jobs)\n\nWrapper for cds.spawn with additional functionality\n\n## Table of Contents\n\n- [Features](#features)\n- [Installing](#installing)\n- [Implementation](#implementation)\n- [License](#license)\n\n## Features\n\n- Block jobs to avoid parallel processing\n- Set context id to job for better monitoring\n- Background jobs\n\n## Installing\n\nUsing npm:\n\n```bash\n$ npm install @amag-ch/cds-jobs\n```\n\nUsing yarn:\n\n```bash\n$ yarn add @amag-ch/cds-jobs\n```\n\n## Implementation\n\n```js\nconst jobs = require('@amag-ch/cds-jobs')\n\njobs.spawn({ every: 1000, blockingId: 'a-blocking-id' }, async () => {\n    // do something\n})\n```\n\nA background job need two processing functions, called selector and executer, which must be given at construction.\nThe job calls the selector and calls afterthen the executer with the selected entries.\nThe 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.\n\nThe job automaticly starts the first time after the cds server is up and running.\n\nIf the selector or executer produces an error, the jobs stopps and reschedule after a defined delay (default: 60000)\n\nThe name or the delay could be changed in the third argument of the constructor.\n```js\nconst { BackgroundJob } = require('@amag-ch/cds-jobs')\n\nconst job = new BackgroundJob(\n    async () => db.read('Table').limit(10).forUpdate(),\n    async (entries) => console.log(entries)\n)\n\njob.start() // only possible, if current cds.context is set\n```\n\n## License\n\n[MIT](LICENSE)","readmeFilename":"README.md"}