The solution to the interview assignment
- Clone this repo:
git clone https://github.com/ichtrojan/carthook.git
- Change directory to the project
cd carthook
- Install dependencies
composer install
- Duplicate
.env.example
cp .env.example .env
-
Modify the database credentials in the
.env
file to suit what you have locally -
Run migrations and seeders
php artisan migrate
NOTE
DO NOT RUN SEEDERS
- Start Queue
php artisan queue:work database
- Run the scheduler
php artisan schedule:run
The scheduler has to be running in the background. On macOS/Unix you should add the following to your .zshrc
or .bashrc
file.
function scheduler () {
while :; do
php artisan schedule:run
echo "Sleeping 60 seconds..."
sleep 60
done
}
The run the scheduler
command in terminal. This will run the Laravel Scheduler every 60 seconds.
Kindly visit the Postman Docs to view the available endpoints.
To run tests, execute:
php artisan test
The API calls to JSONPlaceholder are Scheduled Jobs that run Every 60 Seconds.
On every successful API call, the data returned are stored in the Database and Cached to file for faster access. Ideally, I would have used Redis but choose to skip that to simplify the installation.
The first time an endpoint is being called, there is a 2 seconds delay to enable the Scheduled job to process the API call, cache and store to the database. Subsequent calls to the API should be processed withing 80ms on average.
Hire me 🙂