Attachment: JSON file: "challenge.json".
Write a process that neatly writes the contents of the JSON file away to a database. Preferably as a background task in Laravel. Use of Docker is allowed, but only if it makes it more fun.
We pay particular attention to the design and structure of the code. For example, we'd rather see a solid, neat, easily maintainable solution that doesn't work 100% of the time, than a finished solution that is messy and inimitable. We are particularly interested in the thinking behind your approach.
- [Primary] Make the process such that any time it can be truncated (e.g., by a SIGTERM, power outage, etc.), it can continue in a robust, reliable manner exactly where it last left off (without duplicating data).1
- Design your solution "for growth," taking into account a hypothetical customer who will have new requirements each time.
- Use a solid, but not excessive database model. Code for Eloquent models and relationships are not important here, we are more concerned with the data structure.
- Only process records where the age is between 18 and 65 (or unknown).
As an added challenge, we provide the following for consideration:
- What if the source file suddenly becomes 500 times larger?
- Is the process easily deployed for an XML or CSV file with similar content?
- Suppose that only records need to be processed for which the credit card number contains three consecutive same digits, how would you handle that?
1 Note that there is no guarantee that there are no duplicate records in the source file (there are no guaranteed unique (combinations of) properties) - and all duplicates do need to be replicated 1-to-1 in the database.
- Docker
- Laravel Sail(Configuring A Bash Alias)
$ git clone https://github.com/robersonfaria/job-application-challenge.git
$ cp .env.example .env
$ docker run --rm \
-u "$(id -u):$(id -g)" \
-v $(pwd):/var/www/html \
-w /var/www/html \
laravelsail/php81-composer:latest \
composer install --ignore-platform-reqs
In the scale parameter you can choose the number of containers that will process the queue, the more containers the faster the processing.
$ sail up --scale laravel.queue=8
$ sail artisan migrate
Basic flow, load the challenge.json file and record the data in the database(only people between 18 and 65 years old).
$ sail artisan challenge:process-file
Basic flow, load the challenge.json file and filter only customers with card number with 3 consecutive equal digits
$ sail artisan challenge:process-file --3digits
Generate csv, xml or json file with faker data:
$ sail artisan challenge:generate-file --records=10 filename.csv
Process other files (non-default):
$ sail artisan challenge:process-file --filename=other_file.csv
$ sail composer phpunit
The coverage report can be consulted at ./coverage/index.html