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
Exemplo n.º 2
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
Exemplo 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
Exemplo n.º 4
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