- After git clone and cd, run
npm install
. - Put the
aftership.json
file underconfig
folder. - Then run:
NODE_ENV=aftership node index.js
- DOWNLOAD this repository to your own Github public repository.
- Create a new repo, name it by using this shortGUID generator
- Do NOT fork, as other candidates would be able to see your solution easily.
- Use beanstalkd, mongodb, nodejs
- Get the xe.com exchange rate, store it in mongodb for every 1 min.
Code a currency exchagne rate worker
- Input currency from USD, to HKD
- Get USD to HKD currency every 1 min, save 10 successful result to mongodb.
- If any problem during the get rate attempt, retry it delay with 3s
- If failed more than 3 times, give up the job.
Scale horizontally (can run in more than 1 process in many different machines)
- Seed your job in beanstalkd, tube_name = your_github_username
Sample beanstalk payload for getting HKD to USD currency, you can use any format or content to fit your need.
{
"from": "HKD",
"to": "USD"
}
-
Code a nodejs worker, get the job from beanstalkd, get the data from xe.com and save it to mongodb. Exchange rate need to be round off to
2
decmicals inSTRING
type.a. If request fail, reput to the tube and delay with 3s.
b. If request is done, reput to the tube and delay with 60s.
{
"from": "HKD",
"to": "USD",
"created_at": new Date(1347772624825),
"rate": "0.13"
}
-
Stop the task if you tried 10 succeed attempt or 3 failed attempt.
-
NOTICE that the above bs payload is just an example, you should make sure your script can be run as
distributed
system (multiple instances, multi process), and also able to get MULTIPLE currenies if needed. Not only HKD to USD. -
You are coding the
consumer
worker, NEVER use your worker to seed the data.
-
beanstalkd server is setup for you already, make a JSON request to this:
/POST http://challenge.aftership.net:9578/v1/beanstalkd
header: aftership-api-key: a6403a2b-af21-47c5-aab5-a2420d20bbec
-
Get a free mongodb server at mongolab
-
You should need fivebeans npm or any tools u like.
-
You may also need Beanstalk console or any tools u like.
-
Our cook book
am9ic0BhZnRlcnNoaXAuY29t