Skip to content

ichtrojan/carthook

Repository files navigation

Carthook

hero

Introduction

The solution to the interview assignment

Installation

  • 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.

Usage

Kindly visit the Postman Docs to view the available endpoints.

Tests

To run tests, execute:

php artisan test

Summary

API Calls

The API calls to JSONPlaceholder are Scheduled Jobs that run Every 60 Seconds.

Data Caching

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.

Database Structure

structure

Initial Call

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.

Conclusion

Hire me 🙂

About

Carthook Interview

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published