Merge branch 'dillon/34.4-jenkins-vapor' into vapor/development

This commit is contained in:
Dillon Ngo
2024-05-25 12:13:37 +08:00
4 changed files with 113 additions and 17 deletions
@@ -0,0 +1,52 @@
<?php
namespace App\Classes\Jobs\Commands\V2;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
class HouseKeepingS3FilesV2CommandJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
Log::info(Carbon::now() . ': Start job - Housekeeping temporary files in S3 Bucket.');
$start = new Carbon();
$s3 = Storage::disk('s3');
$directories = [
'temp',
];
foreach ($directories as $directory) {
$startInner = Carbon::now();
Log::info(Carbon::now() . ' [HouseKeepingS3FilesV2] Start cleaning - ' . $directory);
$objects = $s3->allFiles($directory);
foreach ($objects as $object) {
$s3->delete($object);
Log::info('[HouseKeepingS3FilesV2] Deleted object: ' . $object);
}
Log::info('[HouseKeepingS3FilesV2] All files have been deleted.');
$endInner = Carbon::now();
$elapsedTime = $startInner->diff($endInner)->format('%H:%I:%S');
Log::info(Carbon::now() . ' [HouseKeepingS3FilesV2] Process ended. ElapsedTime: ' . $elapsedTime);
}
$end = new Carbon();
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
Log::info(Carbon::now() . ': End job - Housekeeping temporary files in S3 Bucket. ElapsedTime: ' . $elapsedTime . '.');
}
}
@@ -20,14 +20,28 @@ class Convert1688PurchaseOrderToProductList
$productList = [];
$shipping = 0;
$discount = 0;
$text = "";
$filepath = "";
$filesystemDriver = Storage::getDefaultDriver();
$file = $file->file->file_info->original->file;
if($filesystemDriver === 's3'){
$fileContent = Storage::disk('s3')->get($file);
$filepath = storage_path('app/temp.pdf');
file_put_contents($filepath, $fileContent);
}
else{
$filepath = Storage::disk('documents')->path($file);
}
try {
$pdf = $parser->parseFile(Storage::disk('documents')->path($file->file->file_info->original->file));
$pdf = $parser->parseFile($filepath);
$text = $pdf->getText();
} catch (Exception $exception) {
throw new MalformedRequestException('Invalid file format.');
}
$text = $pdf->getText();
if(str_contains($text, '订单详情单')) throw new MalformedRequestException('Can\'t process non english documents');
$tables = explode('Amount (yuan)', $text);
@@ -0,0 +1,23 @@
<?php
namespace App\Console\Commands\V2;
use App\Classes\Jobs\Commands\V2\HouseKeepingS3FilesV2CommandJob;
use Illuminate\Console\Command;
class HouseKeepingS3FilesV2Command extends Command
{
protected $signature = 'housekeeping-s3-files-command';
protected $description = 'Housekeeping temporary files in S3 Bucket';
public function __construct()
{
parent::__construct();
}
public function handle()
{
HouseKeepingS3FilesV2CommandJob::dispatch();
}
}
+22 -15
View File
@@ -37,27 +37,34 @@ class Kernel extends ConsoleKernel
->everyFiveMinutes()
->withoutOverlapping();
$schedule->command('email-do-to-vt-command')
->dailyAt('10:00')
$schedule->command('housekeeping-s3-files-command')
->everyFiveMinutes()
->withoutOverlapping();
$schedule->command('seasonal-segmant-company-remove-command')
->dailyAt('01:00')
->withoutOverlapping();
//cief todo: disable commands to avoid unintentional interfering with production starts
// $schedule->command('email-do-to-vt-command')
// ->dailyAt('10:00')
// ->withoutOverlapping();
$schedule->command('delete-bulk-download-files-command')
->hourly()
->withoutOverlapping();
// $schedule->command('seasonal-segmant-company-remove-command')
// ->dailyAt('01:00')
// ->withoutOverlapping();
$schedule->command('new-user-registration-expire-check-command')
//->dailyAt('23:55') //cief todo: original, to be reverted back to this
->everyFifteenMinutes()
->withoutOverlapping();
// $schedule->command('delete-bulk-download-files-command')
// ->hourly()
// ->withoutOverlapping();
$schedule->command('booking-expired-command')
->dailyAt('02:00')
->withoutOverlapping();
// $schedule->command('new-user-registration-expire-check-command')
// //->dailyAt('23:55') //cief todo: original, to be reverted back to this
// ->everyFifteenMinutes()
// ->withoutOverlapping();
// $schedule->command('booking-expired-command')
// ->dailyAt('02:00')
// ->withoutOverlapping();
//cief todo: disable commands to avoid unintentional interfering with production ends
// DISABLED BY DEFAULT
// $schedule->command('purchase-order-autofill-command')
// ->dailyAt('03:00')
// ->withoutOverlapping();