Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle missing file exception in initialize feature vector job #147

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Jobs/InitializeFeatureVectorChunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
use League\Flysystem\UnableToReadFile;

class InitializeFeatureVectorChunk extends GenerateFeatureVectors
{
Expand Down Expand Up @@ -113,7 +114,12 @@ public function getFeatureVectors(Collection $models, string $outputPath): \Gene
$srcPath = ProcessAnnotatedFile::getTargetPath($a);
$tmpPath = tempnam(sys_get_temp_dir(), '');

$thumbnail = $disk->get($srcPath);
try {
$thumbnail = $disk->get($srcPath);
} catch (UnableToReadFile $e) {
continue;
}

if (is_null($thumbnail)) {
continue;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/Jobs/InitializeFeatureVectorChunkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Biigle\VideoAnnotationLabel;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
use League\Flysystem\UnableToReadFile;
use Mockery;
use TestCase;

class InitializeFeatureVectorChunkTest extends TestCase
Expand Down Expand Up @@ -102,6 +104,18 @@ public function testHandleSkipMissingThumbnails()
$this->assertNull(ImageAnnotationLabelFeatureVector::find($al->id));
}

public function testHandleSkipMissingThumbnailsException()
{
$mock = Mockery::mock();
$mock->shouldReceive('get')->andThrow(UnableToReadFile::class);
Storage::shouldReceive('disk')->andReturn($mock);
$al = ImageAnnotationLabel::factory()->create();
$job = new InitializeFeatureVectorChunkStub([$al->annotation_id], []);
$job->output = $al->annotation_id.',"'.json_encode(range(0, 383)).'"';
$job->handle();
$this->assertNull(ImageAnnotationLabelFeatureVector::find($al->id));
}

public function testHandleMultipleLabels()
{
$disk = Storage::fake(config('largo.patch_storage_disk'));
Expand Down