Skip to content

Commit

Permalink
Merge 74e32eb into 4b340fa
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmackay committed Nov 26, 2018
2 parents 4b340fa + 74e32eb commit f6bfd3d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 76 deletions.
7 changes: 0 additions & 7 deletions app/Jobs/ExportPostsBatchJob.php
Expand Up @@ -56,12 +56,5 @@ public function handle(Export $usecase, ExportJobRepository $exportJobRepo)
$batch = $usecase->interact();

Log::debug('Batch completed', [$batch]);

// Check if batches are finished
if ($exportJobRepo->areBatchesFinished($this->jobId)) {
Log::debug('All batches finished', ['jobId' => $this->jobId]);
// if yes, queue combine job
dispatch(new CombineExportedPostBatchesJob($this->jobId));
}
}
}
7 changes: 7 additions & 0 deletions app/Jobs/ExportPostsJob.php
Expand Up @@ -7,6 +7,7 @@
use Ushahidi\Core\Entity\ExportJobRepository;
use Ushahidi\App\Multisite\MultisiteAwareJob;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Carbon;

class ExportPostsJob extends Job
{
Expand Down Expand Up @@ -88,5 +89,11 @@ public function handle(PostCount $usecase, ExportJobRepository $exportJobRepo)
($batchNumber === 0)
));
}

// Queue combine job in 1 min
dispatch(
(new CombineExportedPostBatchesJob($this->jobId))
->delay(Carbon::now()->addMinutes(1))
);
}
}
69 changes: 0 additions & 69 deletions tests/unit/App/Jobs/ExportPostsBatchJobTest.php
Expand Up @@ -17,18 +17,6 @@
*/
class ExportPostsBatchJobTest extends TestCase
{
protected function mockDispatcher()
{
unset($this->app->availableBindings['Illuminate\Contracts\Bus\Dispatcher']);
$mock = M::mock('Illuminate\Bus\Dispatcher[dispatch]', [$this->app]);
$this->app->instance(
'Illuminate\Contracts\Bus\Dispatcher',
$mock
);

return $mock;
}

public function testExportPostsBatchJob()
{
$jobId = 33;
Expand Down Expand Up @@ -69,63 +57,6 @@ public function testExportPostsBatchJob()
]
]);

$exportJobRepo->shouldReceive('areBatchesFinished')
->with($jobId)
->once()
->andReturn(false);

$job->handle($usecase, $exportJobRepo);
}

public function testExportFinalBatch()
{
$jobId = 33;
$batchNumber = 2;
$offset = 200;
$limit = 200;
$includeHeader = true;
$job = new ExportPostsBatchJob($jobId, $batchNumber, $offset, $limit, $includeHeader);

$dispatcher = $this->mockDispatcher();
$dispatcher->shouldReceive('dispatch')->once()
->with(M::type(\Ushahidi\App\Jobs\CombineExportedPostBatchesJob::class));

$usecase = M::mock(\Ushahidi\Core\Usecase\Post\Export::class);
$exportJobRepo = M::mock(\Ushahidi\Core\Entity\ExportJobRepository::class);

$usecase->shouldReceive('setFilters')
->once()
->with([
'limit' => $limit,
'offset' => $offset,
'add_header' => $includeHeader
])
->andReturn($usecase);

$usecase->shouldReceive('setIdentifiers')
->once()
->with([
'job_id' => $jobId,
'batch_number' => $batchNumber
])
->andReturn($usecase);

$usecase->shouldReceive('interact')
->once()
->andReturn([
[
'filename' => 'filename.jpg',
'id' => 55,
'rows' => 200,
'status' => 'completed'
]
]);

$exportJobRepo->shouldReceive('areBatchesFinished')
->with($jobId)
->once()
->andReturn(true);

$job->handle($usecase, $exportJobRepo);
}
}
2 changes: 2 additions & 0 deletions tests/unit/App/Jobs/ExportPostsJobTest.php
Expand Up @@ -36,6 +36,8 @@ public function testExportPostsJob()
$dispatcher = $this->mockDispatcher();
$dispatcher->shouldReceive('dispatch')->times(5)
->with(M::type(\Ushahidi\App\Jobs\ExportPostsBatchJob::class));
$dispatcher->shouldReceive('dispatch')->times(1)
->with(M::type(\Ushahidi\App\Jobs\CombineExportedPostBatchesJob::class));

$usecase = M::mock(\Ushahidi\Core\Usecase\Export\Job\PostCount::class);
$exportJobRepo = M::mock(\Ushahidi\Core\Entity\ExportJobRepository::class);
Expand Down

0 comments on commit f6bfd3d

Please sign in to comment.