In modern computing environments, efficient task scheduling, management, and monitoring are crucial. This project aims to design and implement a robust and scalable backend for a job scheduling system.
Install job scheduler system with npm
cd job scheduler system
npm install
POST /api/submitJob
Parameter | Type | Description |
---|---|---|
api_key |
string |
Required. API key |
GET /api/jobs/:job_id
Parameter | Type | Description |
---|---|---|
job_id |
string |
Required. Id of item to fetch |
PUT /api/jobs/:job_id
Parameter | Type | Description |
---|---|---|
job_id |
string |
Required. ID of the job to reschedule |
DELETE /api/jobs/:job_id
Parameter | Type | Description |
---|---|---|
job_id |
string |
Required. ID of the job to cancel |
GET /api/jobs
Parameter | Type | Description |
---|---|---|
api_key |
string |
Required. API Key |
GET /api/jobs/:job_id/status
Parameter | Type | Description |
---|---|---|
job_id |
string |
Required. ID of the job to fetch status |
This Node.js application manages scheduling and execution of jobs, including both recurring and one-time jobs. It leverages the following libraries:
node-schedule
: For scheduling jobs based on cron expressions.nodemailer
(optional): For sending notification emails upon job failures.
Functionality Overview:
- Recurring Jobs:
- Schedules jobs based on cron expressions defined in the
Job
model. - Uses
node-schedule
to schedule job execution at specified intervals.
- Schedules jobs based on cron expressions defined in the
- One-Time Jobs:
- Schedules jobs based on a specific
scheduled_time
property in theJob
model. - Executes the job at the designated time.
- Schedules jobs based on a specific
- Job Execution:
- Manages the execution flow of both recurring and one-time jobs.
- Implements a retry mechanism for failed recurring jobs (configurable
max_attempts
in theJob
model).
- Job Failure Handling:
- Logs error messages for failed jobs.
- Optionally sends notification emails about failures using
sendNotificationEmail
(requires configuration).
To run tests, run the following command
npx jest
For any issues or questions, please contact [email protected].