Skip to content

Commit

Permalink
fix: dispatch CleanupUnusedUploadedFile job only in async queue conne…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
mansoorkhan96 committed Apr 22, 2024
1 parent ec88e6c commit 7c027e6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions src/Actions/UnsplashPickerAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/Jobs/CleanupUnusedUploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 7c027e6

Please sign in to comment.