Create a job queue whose workers fetch data from a URL and store the results in a database. The job queue should expose a REST API for adding jobs and checking their status / results.
Install dependencies:
$ npm installPlease ensure that you have MongoDB and Redis installed and running before starting the server.
Start the server:
$ npm startServer should be started on port 3000.
Create a new job
Example request:
POST /jobs
Content-Type: application/json
{"url": "http://www.google.com"}Example Successful Response:
{
"id": "59a6a8559a77502060e6adf0",
"status": "pending",
"timestamp": "2017-08-30T11:58:13.371Z",
"url": "http://www.google.com"
}Read a job using it's job ID
Example request:
GET /jobs/59a644cf91257c071849eaeExample Successful Response With Completed Job:
HTTP 200 OK
Content-Type: application/json
{
"_id": "59a644cf91257c071849eae5",
"url": "http://www.google.com",
"timestamp": "2017-08-30T04:53:35.984Z",
"status": "completed",
"response": "<!doctype html><html>...</html>"
}Example Successful Response with Pending/Ongoing Job:
HTTP 200 OK
Content-Type: application/json
{
"_id": "59a644cf91257c071849eae5",
"url": "http://www.google.com",
"timestamp": "2017-08-30T04:53:35.984Z",
"status": "pending" OR "ongoing"
}