Skip to content

Commit

Permalink
Merge pull request #41 from biigle/sim-sort
Browse files Browse the repository at this point in the history
Largo sort
  • Loading branch information
mzur authored Jan 25, 2024
2 parents 73669e7 + e7841a6 commit aad892a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
40 changes: 22 additions & 18 deletions src/Jobs/PostprocessVolumeImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Biigle\Modules\Sync\Jobs;

use Biigle\ImageAnnotation;
use Biigle\Image;
use Biigle\Jobs\Job;
use Biigle\Jobs\ProcessNewVolumeFiles;
use Biigle\Modules\Largo\Jobs\GenerateImageAnnotationPatch;
use Biigle\Modules\Largo\Jobs\GenerateVideoAnnotationPatch;
use Biigle\VideoAnnotation;
use Biigle\Modules\Largo\Jobs\ProcessAnnotatedImage;
use Biigle\Modules\Largo\Jobs\ProcessAnnotatedVideo;
use Biigle\Video;
use Biigle\Volume;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
Expand Down Expand Up @@ -47,24 +47,28 @@ public function handle()
ProcessNewVolumeFiles::dispatch($volume);
});

if (class_exists(GenerateImageAnnotationPatch::class)) {
ImageAnnotation::join('images', 'images.id', '=', 'image_annotations.image_id')
->whereIn('images.volume_id', $this->ids)
->select('image_annotations.id')
->eachById(function ($annotation) {
GenerateImageAnnotationPatch::dispatch($annotation)
// Give the ProcessNewVolumeFiles jobs a head start so the file thumbnails are
// generated (mostly) before the annotation thumbnails.
$delay = now()->addSeconds(30);

if (class_exists(ProcessAnnotatedImage::class)) {
Image::whereIn('images.volume_id', $this->ids)
->whereHas('annotations')
->eachById(function ($image) use ($delay) {
ProcessAnnotatedImage::dispatch($image)
->delay($delay)
->onQueue(config('largo.generate_annotation_patch_queue'));
}, 1000, 'image_annotations.id', 'id');
}, 1000);
}

if (class_exists(GenerateVideoAnnotationPatch::class)) {
VideoAnnotation::join('videos', 'videos.id', '=', 'video_annotations.video_id')
->whereIn('videos.volume_id', $this->ids)
->select('video_annotations.id')
->eachById(function ($annotation) {
GenerateVideoAnnotationPatch::dispatch($annotation)
if (class_exists(ProcessAnnotatedVideo::class)) {
Video::whereIn('videos.volume_id', $this->ids)
->whereHas('annotations')
->eachById(function ($video) use ($delay) {
ProcessAnnotatedVideo::dispatch($video)
->delay($delay)
->onQueue(config('largo.generate_annotation_patch_queue'));
}, 1000, 'video_annotations.id', 'id');
}, 1000);
}
}
}
18 changes: 9 additions & 9 deletions tests/Jobs/PostprocessVolumeImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Biigle\Tests\Modules\Sync\Jobs;

use Biigle\Jobs\ProcessNewVolumeFiles;
use Biigle\Modules\Largo\Jobs\GenerateImageAnnotationPatch;
use Biigle\Modules\Largo\Jobs\GenerateVideoAnnotationPatch;
use Biigle\Modules\Largo\Jobs\ProcessAnnotatedImage;
use Biigle\Modules\Largo\Jobs\ProcessAnnotatedVideo;
use Biigle\Modules\Sync\Jobs\PostprocessVolumeImport;
use Biigle\Tests\ImageAnnotationTest;
use Biigle\Tests\ImageTest;
Expand All @@ -20,34 +20,34 @@ public function testHandleVolumeImages()
$job = new PostprocessVolumeImport(collect([$image->volume]));
$job->handle();
Queue::assertPushed(ProcessNewVolumeFiles::class);
Queue::assertNotPushed(GenerateImageAnnotationPatch::class);
Queue::assertNotPushed(ProcessAnnotatedImage::class);
}

public function testHandleImageAnnotationPatches()
{
if (!class_exists(GenerateImageAnnotationPatch::class)) {
$this->markTestSkipped('Requires '.GenerateImageAnnotationPatch::class);
if (!class_exists(ProcessAnnotatedImage::class)) {
$this->markTestSkipped('Requires '.ProcessAnnotatedImage::class);
}

$annotation = ImageAnnotationTest::create();
$job = new PostprocessVolumeImport(collect([$annotation->image->volume]));
$job->handle();
// One job for the creation of the annotation and one job by
// PostprocessVolumeImport.
$this->assertCount(2, Queue::pushed(GenerateImageAnnotationPatch::class));
$this->assertCount(2, Queue::pushed(ProcessAnnotatedImage::class));
}

public function testHandleVideoAnnotationPatches()
{
if (!class_exists(GenerateVideoAnnotationPatch::class)) {
$this->markTestSkipped('Requires '.GenerateVideoAnnotationPatch::class);
if (!class_exists(ProcessAnnotatedVideo::class)) {
$this->markTestSkipped('Requires '.ProcessAnnotatedVideo::class);
}

$annotation = VideoAnnotationTest::create();
$job = new PostprocessVolumeImport(collect([$annotation->video->volume]));
$job->handle();
// One job for the creation of the annotation and one job by
// PostprocessVolumeImport.
$this->assertCount(2, Queue::pushed(GenerateVideoAnnotationPatch::class));
$this->assertCount(2, Queue::pushed(ProcessAnnotatedVideo::class));
}
}

0 comments on commit aad892a

Please sign in to comment.