Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
vitgrams committed Nov 27, 2024
1 parent 9d84bcf commit 6fa4ecb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
2 changes: 0 additions & 2 deletions config/auto-doc.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@
*/
'documentation_viewer' => env('SWAGGER_SPEC_VIEWER', 'swagger'),

'tmp_dir' => storage_path('tmp_documentation'),

'drivers' => [
'local' => [
'class' => LocalDriver::class,
Expand Down
7 changes: 2 additions & 5 deletions src/Drivers/BaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace RonasIT\AutoDoc\Drivers;

use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\ParallelTesting;
use RonasIT\AutoDoc\Contracts\SwaggerDriverContract;

Expand All @@ -12,11 +11,9 @@ abstract class BaseDriver implements SwaggerDriverContract

public function __construct()
{
$tmpDir = config('auto-doc.tmp_dir');

$this->tempFilePath = ($token = ParallelTesting::token())
? $tmpDir . "/temp_documentation_{$token}.json"
: $tmpDir . '/temp_documentation.json';
? storage_path("/temp_documentation_{$token}.json")
: storage_path('/temp_documentation.json');
}

public function saveTmpData($data): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public function notify(Finished $event): void
{
$this->createApplication();

if ($token = ParallelTesting::token()) {
$this->mergeTempDocumentation($token);
} else {
app(SwaggerService::class)->saveProductionData();
if (ParallelTesting::token()) {
$this->mergeTempDocumentation();
}

app(SwaggerService::class)->saveProductionData();
}

protected function createApplication(): void
Expand All @@ -32,9 +32,7 @@ protected function createApplication(): void

protected function mergeTempDocumentation(): void
{
$swaggerService = app(SwaggerService::class);

$lockHandle = fopen(config('auto-doc.tmp_dir') . '/lock.lock', 'c+');
$lockHandle = fopen(storage_path('/temp_documentation.json'), 'c+');

$locked = false;

Expand All @@ -44,7 +42,12 @@ protected function mergeTempDocumentation(): void
usleep(10);
}

$swaggerService->saveProductionData();
$parallelToken = ParallelTesting::token();

$sharedDocContent = json_decode(stream_get_contents($lockHandle), true);
$workerDocContent = json_decode(file_get_contents(storage_path("/temp_documentation_{$parallelToken}.json")));

app(SwaggerService::class)->mergeOpenAPIDocs($sharedDocContent, $workerDocContent);

flock($lockHandle, LOCK_UN);
}
Expand Down

0 comments on commit 6fa4ecb

Please sign in to comment.