{"_id":"@code-crafts/job-scheduler","name":"@code-crafts/job-scheduler","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@code-crafts/job-scheduler","version":"1.0.0","description":"A simple and effective job scheduling module for Node.js, designed to manage and execute tasks based on cron-like schedules. This module utilizes `node-schedule` for precise timing and flexibility, making it ideal for applications that require specific ti","author":{"name":"Khan Cirhan"},"types":"build/src/index.d.ts","exports":{".":"./build/src/index.js"},"scripts":{"dev":"nodemon playground.ts","build":"npx tsc --p ./tsconfig.build.json","prepublishOnly":"npm run build","npmPublish":"npm publish --access public"},"keywords":["nodejs","job scheduler","task scheduler","cron","node-schedule"],"license":"ISC","repository":{"type":"git","url":"git+https://github.com/codecrafts-co/job-scheduler.git"},"devDependencies":{"@types/node":"^20.12.12","@types/node-schedule":"^2.1.7","nodemon":"^3.1.4","ts-node":"^10.9.2","typescript":"^5.4.5"},"dependencies":{"node-schedule":"^2.1.1"},"_id":"@code-crafts/job-scheduler@1.0.0","gitHead":"2719035bd5b3fd15adaba487cddbaac9d7677554","bugs":{"url":"https://github.com/codecrafts-co/job-scheduler/issues"},"homepage":"https://github.com/codecrafts-co/job-scheduler#readme","_nodeVersion":"20.12.2","_npmVersion":"10.5.0","dist":{"integrity":"sha512-BM2vbvujgzrXmq6p3LjIIy0230M0oBuisn2U2D4z+uChZYT3X47BjgDv+3GxBlCztaJA0dX1zJxcfHVbUp7HFw==","shasum":"7f920f4854a4d280166f34f7aac32d2e8aa83ec7","tarball":"https://registry.npmjs.org/@code-crafts/job-scheduler/-/job-scheduler-1.0.0.tgz","fileCount":9,"unpackedSize":27648,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDjb1wbgPC486eBh/SELE6f08Toz6BL20BaORUhcmJRzgIhAIbGLzsF5ipkipWdz9JF4rqWkfAoOhirxlkdZ9zPaebb"}]},"_npmUser":{"name":"code-crafts","email":"codecrafts.co@gmail.com"},"directories":{},"maintainers":[{"name":"code-crafts","email":"codecrafts.co@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/job-scheduler_1.0.0_1722780269835_0.7684645563584838"},"_hasShrinkwrap":false}},"time":{"created":"2024-08-04T14:04:29.709Z","1.0.0":"2024-08-04T14:04:30.034Z","modified":"2024-08-04T14:04:30.370Z"},"maintainers":[{"name":"code-crafts","email":"codecrafts.co@gmail.com"}],"description":"A simple and effective job scheduling module for Node.js, designed to manage and execute tasks based on cron-like schedules. This module utilizes `node-schedule` for precise timing and flexibility, making it ideal for applications that require specific ti","homepage":"https://github.com/codecrafts-co/job-scheduler#readme","keywords":["nodejs","job scheduler","task scheduler","cron","node-schedule"],"repository":{"type":"git","url":"git+https://github.com/codecrafts-co/job-scheduler.git"},"author":{"name":"Khan Cirhan"},"bugs":{"url":"https://github.com/codecrafts-co/job-scheduler/issues"},"license":"ISC","readme":"\n# @code-crafts/job-scheduler\n\nA simple and effective job scheduling module for Node.js, designed to manage and execute tasks based on cron-like schedules. This module utilizes `node-schedule` for precise timing and flexibility, making it ideal for applications that require specific timing tasks.\n\n## Features\n\n- **Cron-like Scheduling:** Schedule tasks to run at specific times or intervals using cron syntax.\n- **Dynamic Job Management:** Dynamically add, cancel, and invoke scheduled jobs.\n- **Graceful Shutdown:** Includes a method to gracefully shut down all scheduled jobs, ensuring no tasks are left hanging.\n\n## Installation\n\nInstall the package using npm:\n\n```bash\nnpm install @code-crafts/job-scheduler\n```\n\n## Usage\n\n### Basic Setup\n\n#### Create a Scheduler Instance\n\n```javascript\nimport { JobScheduler } from '@code-crafts/job-scheduler';\n\nconst jobScheduler = new JobScheduler();\n```\n\n#### Schedule Jobs\n\nSchedule a job to run every 10 seconds:\n\n```javascript\njobScheduler.schedule('test', '*/10 * * * * *', () => {\n    console.log('Job test called');\n});\n```\n\nSchedule another job to run every 5 seconds:\n\n```javascript\njobScheduler.schedule('test2', '*/5 * * * * *', () => {\n    console.log('Job test2 called');\n});\n```\n\n#### Manually Invoke a Job\n\n```javascript\nsetTimeout(() => {\n    jobScheduler.invoke('test');\n}, 1000);\n```\n\n#### Cancel a Job\n\n```javascript\nsetTimeout(() => {\n    jobScheduler.cancel('test2');\n}, 6000);\n```\n\n#### Destroy the Scheduler\n\n```javascript\njobScheduler.destroy();\n```\n\n### API\n\n- **schedule(jobName: string, spec: string, cb: Function)**: Schedules a new job.\n- **cancel(jobName: string)**: Cancels a scheduled job.\n- **invoke(jobName: string)**: Manually triggers a scheduled job.\n- **destroy()**: Gracefully shuts down all scheduled jobs and clears the job map.\n\n## Examples\n\nHere's a complete example of setting up the scheduler, scheduling jobs, and then cleaning up:\n\n```javascript\nconst scheduler = new JobScheduler();\n\nscheduler.schedule('minuteJob', '0 * * * * *', () => {\n    console.log('This job runs every minute.');\n});\n\nsetTimeout(() => {\n    scheduler.invoke('minuteJob');\n}, 5000);\n\nsetTimeout(() => {\n    scheduler.cancel('minuteJob');\n    scheduler.destroy();\n}, 10000);\n```\n\n## Repository\n\nFind the source code and contribute on [GitHub](https://github.com/codecrafts-co/job-scheduler).\n\n## License\n\nThis project is licensed under the ISC License - see the LICENSE file for details.\n","readmeFilename":"README.md"}