repo for nomisma backend code challenge
This is a project for nomisma backend code challenge. Read the challenge guideline at docs section.
Build with Express
The schedule should be decoupled from specific business logic in order to reuse.
So it has an executor option to define what you want to do, sending email or doing something else.
The email service should like an adapter
, provide consistent interface for different email service providers.
And should not care about which email service is actually used when call it from outside.
Production: http://raychenfj.me:3007
url: /api/v1/tasks
method: GET
output:
[
{
"to": "example@example.com", // recipient's email
"content": "hello world", // email content
"subject": "hello world", // email subject
"timestamp": 1544065545639, // timestamp, when the email should be send
"immediate": false, // send it immediately
"id": "88672290-ba4a-4689-aaba-c6924ea00b88", // auto-gen uuid
"status": "complete", // status, can be pending/complete/fail
"retry": 0 // retry times
}
]
url: /api/v1/tasks
method: POST
input:
body: {
"to": "example@example.com", // recipient's emaild
"content": "hello world", // email content
"subject": "hello world", // email subject
"timestamp": 1544111630082, // unix timestamp
}
output:
will send schedule task successfully
when success
npm run install
# or
yarn
npm run test
-
Rename
config.example.js
toconfig.js
-
Fill api keys for both development and production env in
config.js
( get your api keys here SendGrid and SparkPost ) -
Then run
npm run start:dev/prod
for development/production env
bash publish.sh
Can re-implement this email service by using producer consumer pattern. Can provide improve performance when payload and concurrency are high.
The web service works as producer, it constantly add new tasks to some queue, like RabbitMQ
.
And the schedule as a worker or consumer, constantly fetch tasks from queue when it's idle or payload is low.
Create more producers and consumers to scale.
Doc in OpenApi can provide some benefits.
It's json format and be easily parsed.
What I come up with is auto-generating some frontend api code.