Esempio n. 1
0
    def test_save_assembly_job_should_update_job(self):
        study = mgnify.create_study_obj(study_data)
        run = mgnify.create_run_obj(study, run_data)

        assembler = Assembler(name='metaspades', version='3.12.0')
        assembler.save()
        status = AssemblyJobStatus(description='pending')
        status.save()
        status2 = AssemblyJobStatus(description='running')
        status2.save()

        assert len(AssemblyJob.objects.all()) == 0
        assembly_job = AssemblyJob(input_size=0, assembler=assembler, status=status, priority=0)
        assembly_job.save()
        RunAssemblyJob(run=run, assembly_job=assembly_job).save()

        new_priority = 1
        mgnify.save_assembly_job(run, 0, assembler.name, assembler.version, status2, new_priority)

        assert len(RunAssemblyJob.objects.all()) == 1
        assembly_jobs = AssemblyJob.objects.all()
        assert len(assembly_jobs) == 1
        updated_assembly_job = assembly_jobs[0]
        assert updated_assembly_job.pk == assembly_job.pk
        assert updated_assembly_job.status.pk == status2.pk
        assert updated_assembly_job.priority == new_priority
    def create_assembly_job(self,
                            run,
                            total_size,
                            status,
                            assembler_name,
                            assembler_version=None,
                            priority=0):
        try:
            if not assembler_version:
                assembler_version = self.get_latest_assembler_version(
                    assembler_name)
            assembler = Assembler.objects.using(self.database).get(
                name=assembler_name, version=assembler_version)
        except ObjectDoesNotExist:
            assembler = Assembler(name=assembler_name,
                                  version=assembler_version)
            assembler.save(using=self.database)

        if isinstance(status, str):
            status = AssemblyJobStatus.objects.using(
                self.database).get(description=status)
        job = AssemblyJob(assembler=assembler,
                          status=status,
                          input_size=total_size,
                          priority=priority)
        job.save(using=self.database)
        RunAssemblyJob(assembly_job=job, run=run).save(using=self.database)
        return job
Esempio n. 3
0
    def test_get_pending_assembly_jobs_should_return_all_pending_jobs(self):
        status = AssemblyJobStatus(description='pending')
        status.save()

        assembler = Assembler(name='metaspades', version='3.12.0')
        assembler.save()

        assert len(AssemblyJob.objects.all()) == 0
        AssemblyJob(directory='/dir', status=status, priority=0, assembler=assembler, input_size=3).save()
        AssemblyJob(directory='/dir', status=status, priority=1, assembler=assembler, input_size=4).save()
        assert len(mgnify.get_pending_assembly_jobs()) == 2
Esempio n. 4
0
    def test_create_assembly_job_should_set_latest_assembler(self):
        study = mgnify.create_study_obj(study_data)
        run = mgnify.create_run_obj(study, run_data)
        latest_version = '3.12.0'
        _ = Assembler(name='metaspades', version='3.11.1').save()
        _ = Assembler(name='metaspades', version=latest_version).save()

        status = AssemblyJobStatus(description='PENDING')
        status.save()
        mgnify.create_assembly_job(run, 0, status, 'metaspades')

        assembly_jobs = AssemblyJob.objects.all()
        assert len(assembly_jobs) == 1
        assembly_job = assembly_jobs[0]
        assert assembly_job.assembler.version == latest_version
Esempio n. 5
0
    def test_get_pending_assembly_jobs_should_order_jobs_by_decreasing_priority(self):
        status = AssemblyJobStatus(description='pending')
        status.save()

        assembler = Assembler(name='metaspades', version='3.12.0')
        assembler.save()

        assert len(AssemblyJob.objects.all()) == 0
        job1 = AssemblyJob(directory='/dir', status=status, priority=3, assembler=assembler, input_size=3)
        job1.save()
        job2 = AssemblyJob(directory='/dir', status=status, priority=1, assembler=assembler, input_size=4)
        job2.save()

        pending_jobs = mgnify.get_pending_assembly_jobs()
        assert len(pending_jobs) == 2
        assert pending_jobs[0].pk == job1.pk
        assert pending_jobs[1].pk == job2.pk
Esempio n. 6
0
    def test_create_assembly_job_should_set_status_from_string_arg(self):
        study = mgnify.create_study_obj(study_data)
        run = mgnify.create_run_obj(study, run_data)
        description = 'PENDING'

        _ = Assembler(name='metaspades', version='3.11.1').save()
        _ = AssemblyJobStatus(description=description).save()
        mgnify.create_assembly_job(run, 0, description, 'metaspades')

        assembly_jobs = AssemblyJob.objects.all()
        assert len(assembly_jobs) == 1
        assembly_job = assembly_jobs[0]
        assert assembly_job.status.description == description
Esempio n. 7
0
 def test_get_latest_assembler_version_should_return_latest_version(self):
     assembler_name = 'metaspades'
     versions = ['3.10.0', '3.11.1', '3.12.0']
     for version in versions:
         Assembler(name=assembler_name, version=version).save()
     assert mgnify.get_latest_assembler_version(assembler_name) == '3.12.0'