feat(convert json): finish

main
seyedmr 3 years ago
parent 35761327f9
commit 70edb273d0
  1. 17
      .env.example
  2. 13
      README.md
  3. 7
      app/Enums/FileFormatEnum.php
  4. 2
      app/Http/Controllers/V1/ConvertController.php
  5. 5
      app/Jobs/ChunkFile.php
  6. 3
      app/Jobs/StoreChunk.php
  7. 1
      app/Services/Chunkers/JsonChunker.php
  8. 9
      docker/runtimes/8.1/supervisord.conf

@ -1,6 +1,6 @@
APP_NAME=Laravel APP_NAME=Laravel
APP_ENV=local APP_ENV=local
APP_KEY= APP_KEY=base64:XzNXQDrJlhmfWWBMxGSbte6eMyNdFkNddlmPLUg55ZY=
APP_DEBUG=true APP_DEBUG=true
APP_URL=http://localhost APP_URL=http://localhost
@ -9,22 +9,22 @@ LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug LOG_LEVEL=debug
DB_CONNECTION=mysql DB_CONNECTION=mysql
DB_HOST=127.0.0.1 DB_HOST=mariadb
DB_PORT=3306 DB_PORT=3306
DB_DATABASE=laravel DB_DATABASE=laravel
DB_USERNAME=root DB_USERNAME=sail
DB_PASSWORD= DB_PASSWORD=password
BROADCAST_DRIVER=log BROADCAST_DRIVER=log
CACHE_DRIVER=file CACHE_DRIVER=file
FILESYSTEM_DISK=local FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync QUEUE_CONNECTION=redis
SESSION_DRIVER=file SESSION_DRIVER=file
SESSION_LIFETIME=120 SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1 MEMCACHED_HOST=memcached
REDIS_HOST=127.0.0.1 REDIS_HOST=redis
REDIS_PASSWORD=null REDIS_PASSWORD=null
REDIS_PORT=6379 REDIS_PORT=6379
@ -56,3 +56,6 @@ VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}" VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}" VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
WWWGROUP=1000
WWWUSER=1000

@ -2,3 +2,16 @@
## installation ## installation
- ``cp .env.example .env``
- ``docker-compose up -d``
- ``docker-compose exec -it laravel.test composer install``
- ``docker-compose exec -it laravel.test php artisan migrate``
- ``docker-compose exec -it laravel.test php artisan test``
## Api route
``POST => http://localhost/api/v1/convert/json``
### Params
'file' => your json file

@ -17,11 +17,4 @@ enum FileFormatEnum: string
return $chunker->handle($uuid, $path); return $chunker->handle($uuid, $path);
} }
public function converter()
{
return match($this){
self::JSON => new JsonToDatabaseConverter
};
}
} }

@ -14,11 +14,13 @@ class ConvertController extends Controller
{ {
public function convert(FileFormatEnum $format, Request $request) public function convert(FileFormatEnum $format, Request $request)
{ {
// save file
Storage::put( Storage::put(
$request->file('file')->getClientOriginalName(), $request->file('file')->getClientOriginalName(),
$request->file('file')->getContent(), $request->file('file')->getContent(),
); );
// push a queue
ChunkFile::dispatch( ChunkFile::dispatch(
Str::uuid(), Str::uuid(),
$request->file('file')->getClientOriginalName(), $request->file('file')->getClientOriginalName(),

@ -37,11 +37,16 @@ class ChunkFile implements ShouldQueue
*/ */
public function handle() public function handle()
{ {
// chunk file (generator)
$chunks = $this->format->chunker($this->uuid, $this->path); $chunks = $this->format->chunker($this->uuid, $this->path);
foreach ($chunks as $key => $chunk) { foreach ($chunks as $key => $chunk) {
StoreChunk::dispatch($chunk); StoreChunk::dispatch($chunk);
// set latest key to redis (cut off handling)
Redis::set($this->uuid . ":latest", $key); Redis::set($this->uuid . ":latest", $key);
} }
// delete file and clear redis
Storage::delete($this->path); Storage::delete($this->path);
Redis::del($this->uuid . ":latest"); Redis::del($this->uuid . ":latest");
} }

@ -43,7 +43,8 @@ class StoreChunk implements ShouldQueue
$chunk = (new Pipeline(app())) $chunk = (new Pipeline(app()))
->through([ ->through([
AgeFilterPipe::class, AgeFilterPipe::class,
CreditCardFilter::class, // uncomment if you want to filter by credit card!
// CreditCardFilter::class,
]) ])
->send($this->changeDateOfBirthToCarbon()) ->send($this->changeDateOfBirthToCarbon())
->thenReturn(); ->thenReturn();

@ -19,6 +19,7 @@ class JsonChunker implements ChunkerInterface
{ {
$chunk = []; $chunk = [];
// get latest key for cut off handling
$latest = Redis::get($uuid . ":latest") ?? 0; $latest = Redis::get($uuid . ":latest") ?? 0;
foreach (Items::fromFile(Storage::path($path), ['decoder' => new ExtJsonDecoder(true)]) as $key => $value) { foreach (Items::fromFile(Storage::path($path), ['decoder' => new ExtJsonDecoder(true)]) as $key => $value) {

@ -12,3 +12,12 @@ stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0 stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0 stderr_logfile_maxbytes=0
[program:php-supervisor]
command=/usr/bin/php /var/www/html/artisan horizon
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

Loading…
Cancel
Save