diff --git a/README.md b/README.md index 7b44ee8..5d65c9e 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Add your Unsplash Client ID to your `.env` file UNSPLASH_CLIENT_ID=your-unsplash-client-id-goes-here ``` -**Note: Package includes a queueable job to clear/delete unused files after 24 hours. Make sure to set your queue connection to any async driver** +**Note: Package includes a queueable job to clear/delete unused files after 24 hours. Make sure to set your queue connection to any async driver. This Job is only dispatched when QUEUE_CONNECTION is not set to `sync`** ```php QUEUE_CONNECTION=database diff --git a/src/Actions/UnsplashPickerAction.php b/src/Actions/UnsplashPickerAction.php index c49e3ed..eb9d1da 100644 --- a/src/Actions/UnsplashPickerAction.php +++ b/src/Actions/UnsplashPickerAction.php @@ -117,12 +117,14 @@ public function uploadImage($arguments, Component $livewire, FileUpload $compone $filePath = Arr::first($component->getState()); - dispatch(new CleanupUnusedUploadedFile( - model: $livewire->getModel(), - column: $component->getStatePath(false), - filePath: $filePath, - diskName: $component->getDiskName() - ))->delay(now()->addDay()); + if (env('QUEUE_CONNECTION') !== 'sync') { + dispatch(new CleanupUnusedUploadedFile( + model: $livewire->getModel(), + column: $component->getStatePath(false), + filePath: $filePath, + diskName: $component->getDiskName() + ))->delay(now()->addDay()); + } } public function getImageSize(): ImageSize diff --git a/src/Jobs/CleanupUnusedUploadedFile.php b/src/Jobs/CleanupUnusedUploadedFile.php index 97ef59e..04a239c 100644 --- a/src/Jobs/CleanupUnusedUploadedFile.php +++ b/src/Jobs/CleanupUnusedUploadedFile.php @@ -41,9 +41,6 @@ public function handle(): void return; } - $pastHourTimestamp = now()->subHour()->timestamp; - if ($pastHourTimestamp > $storage->lastModified($this->filePath)) { - $storage->delete($this->filePath); - } + $storage->delete($this->filePath); } }