Skip to content

Commit

Permalink
Merge pull request #147 from biigle/patch-1
Browse files Browse the repository at this point in the history
Handle missing file exception in initialize feature vector job
  • Loading branch information
mzur authored Feb 5, 2024
2 parents 83ed3cd + e76271f commit 8c38244
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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

0 comments on commit 8c38244

Please sign in to comment.