generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding SelfDeletingTemporaryDirectory
- Loading branch information
1 parent
36ce48a
commit b51c32f
Showing
3 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Spekulatius\LaravelPowertools\Helpers; | ||
|
||
use Spatie\TemporaryDirectory\TemporaryDirectory; | ||
|
||
class SelfDeletingTemporaryDirectory extends TemporaryDirectory | ||
{ | ||
public function __construct(string $location = '') | ||
{ | ||
parent::__construct($location); | ||
|
||
TemporaryDirectoryCleanupJob::dispatch($this) | ||
Check failure on line 13 in src/Helpers/SelfDeletingTemporaryDirectory.php
|
||
->delay(config('powertools.temporary_directory_clean_up')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Spekulatius\LaravelPowertools\Jobs; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Spekulatius\LaravelPowertools\Helpers\SelfDeletingTemporaryDirectory; | ||
|
||
class TemporaryDirectoryCleanupJob implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
public function __construct( | ||
protected SelfDeletingTemporaryDirectory $selfDeletingTemporaryDirectory, | ||
protected array $context = [], | ||
) { | ||
} | ||
|
||
public function handle(): void | ||
{ | ||
try { | ||
$this->selfDeletingTemporaryDirectory->delete(); | ||
} catch (\Exception $e) { | ||
\Log::error('SelfDeletingTemporaryDirectory: Failed to delete temp dir: '.$e->getMessage(), [ | ||
'path' => $this->selfDeletingTemporaryDirectory->path(), | ||
]); | ||
|
||
throw $e; | ||
} | ||
} | ||
} |