def test_find_and_run_next_batch_chunks(mock_import_chunk, batch, valid_user): """Assert that if a batch is not running that this starts the next chunk.""" for chunk_number in range(1, 3): factories.ImporterXMLChunkFactory.create(batch=batch, chunk_number=chunk_number) tasks.find_and_run_next_batch_chunks( batch, None, "PUBLISHED", "REVISION_ONLY", valid_user.username, record_group=None, ) assert batch.chunks.first().status == ImporterChunkStatus.RUNNING assert batch.chunks.last().status == ImporterChunkStatus.WAITING mock_import_chunk.delay.assert_called_once_with( batch.chunks.first().pk, None, "PUBLISHED", "REVISION_ONLY", valid_user.username, record_group=None, )
def test_find_and_run_next_batch_chunks_finished_runs_dependencies( mock_import_chunk, batch_dependency, valid_user, ): """Assert that if a batch has completely finished, it's dependencies start running.""" batch_dependency.depends_on.chunks.update(status=ImporterChunkStatus.DONE) tasks.find_and_run_next_batch_chunks( batch_dependency.depends_on, None, "PUBLISHED", "REVISION_ONLY", valid_user.username, record_group=None, ) batch = batch_dependency.dependent_batch assert list(batch.chunks.values_list("status", flat=True)) == [ ImporterChunkStatus.RUNNING, ] mock_import_chunk.delay.assert_called_once_with( batch.chunks.first().pk, None, "PUBLISHED", "REVISION_ONLY", valid_user.username, record_group=None, )
def test_find_and_run_next_batch_chunks_already_running( mock_setup_chunk_task, batch_dependency, valid_user, ): """Assert that if a batch already has running chunk, nothing happens.""" batch_dependency.depends_on.chunks.update( status=ImporterChunkStatus.RUNNING) batch = batch_dependency.dependent_batch tasks.find_and_run_next_batch_chunks(batch, "PUBLISHED", valid_user.username) mock_setup_chunk_task.assert_not_called() assert list(batch.chunks.values_list("status", flat=True)) == [ ImporterChunkStatus.WAITING, ]
def run_batch( batch: str, status: str, partition_scheme_setting: str, username: str, workbasket_id: str = None, record_group: Sequence[str] = None, ): import_batch = models.ImportBatch.objects.get(name=batch) find_and_run_next_batch_chunks( import_batch, workbasket_id, status, partition_scheme_setting, username, record_group=record_group, )
def run_batch(batch: str, status: str, username: str): import_batch = models.ImportBatch.objects.get(name=batch) find_and_run_next_batch_chunks(import_batch, status, username)