Assignment service provides REST apis for fetch response from a dependent api.
- Check application swagger via the below link after starting application on localhost:8080
- Api can be hit directly from the browser via swagger. Click on Try it out for each api mentioned in the swagger
- Database Status: ping database for health
- Bored Api Response: return 3 pairs of distinct key and assignment values
- Log Distinct Keys: every 15 mins periodically print all distinct keys returned from boredapi
- all rest apis can be hit with swagger
- run the application via steps provided below
- if the application is running on localhost:8080, then open the following swagger url in browser to test out apis
http://127.0.0.1:8080/swagger/index.html#/
- api returns the status of database
- use the following curl to hit health api
curl --location 'http://localhost:8080/health/v1/status'
- api returns 3 unique key and assignment pair from boredapi.com
- if duplicate keys are returned from boredapi.com then assignment api also throws duplicate error to end client
- use the following curl to hit assignment api
curl --location 'http://localhost:8080/home/v1/activities'
- every 15 mins scheduler picks all distinct keys returned from boredapi.com and was saved in db
- logs are printed in file
- use the following log format to get those logs from file
- console logs can also be found
ps aux | grep "PollActivityOperation"
- example as follows
{"level":"info","path":"Cron-PollActivity","responseBody":"[{\"count\":3,\"key\":\"8550768\"},{\"count\":2,\"key\":\"4266522\"},{\"count\":2,\"key\":\"6825484\"},{\"count\":2,\"key\":\"7091374\"},{\"count\":2,\"key\":\"3456114\"}]","time":"2023-06-05T02:15:00+05:30","message":"PollActivityOperation: success result"}
- gracefull shutdown of resources are handled
- there is rate limit check on the number of times boredapi.com can be called which is 10tps. Its configurable via the app configuration file
- the number of activity count to be returned via '/home/v1/activities' api can also be configured but it most be noted that the api timeout should also be increased
- application logs are found in Logs directory which is configured via app config
- db schema can be found inside './resources' directory
To run the application, you need to use the following instructions
- Setup postgres server using the configuration mentioned in ./resources/dev/database.yml file
- Create table using the schema mentioned in ./resources/schema/1.sql
- Run go mod tidy and go mod vendor from the project's root directory to load all dependencies
- Run go build -o main command to build the service
- Run ./main --port 8080 --env dev --base-config-path ./resources command to start the service
- Note: the configurations are present in the env directory inside the base config path directory
- Note: logs will be printed in the mentioned log path as per the config provided. Log rotation is also handled.
To run the application, you need to use the following instructions
- Facing problem staring the postgres dependency container
You will have to provide proper comments to that API as per the documentation mentioned here. Once you have done that, you will have to run the following command to update the documentation.
make swagger
That's it, now just run the application and browse http://localhost:8080/swagger/index.html
to view your changes.
- run the following make command
- test cover profile is generated which can be viewed in any browser
make test