Exemplo n.º 1
0
 async def test_run_job(self):
     drone = DummyDrone()
     job = Job(resources={"walltime": 50}, used_resources={"walltime": 10})
     assert float("inf") == job.waiting_time
     async with Scope() as scope:
         scope.do(job.run(drone))
     assert 10 == time
     assert 0 == job.waiting_time
     assert job.successful
Exemplo n.º 2
0
    async def _run_job(self, job: Job, kill: bool):
        """
        Method manages to start a job in the context of the given drone.
        The job is started regardless of the available resources. The resource
        allocation takes place after starting the job and the job is killed if the
        drone's overall resources are exceeded. In addition, if the `kill` flag is
        set, jobs are killed if the resources they use exceed the resources they
        requested.
        Then the end of the job's execution is awaited and the drones status
        known to the scheduler is changed.

        :param job: the job to start
        :param kill: if True, a job is killed when used resources exceed
                     requested resources
        """
        job.drone = self
        async with Scope() as scope:
            from lapis.monitor import sampling_required

            self._utilisation = self._allocation = None

            job_execution = scope.do(job.run(self))
            self.jobs += 1
            if job._cached_data:
                self.jobs_with_cached_data += 1
            try:
                async with self.resources.claim(**job.resources):
                    await sampling_required.put(
                        DroneStatusCaching(
                            repr(self),
                            self.pool_resources["cores"],
                            self.theoretical_available_resources["cores"],
                            self.jobs_with_cached_data,
                        ))
                    await sampling_required.put(self)
                    if kill:
                        for resource_key in job.resources:
                            try:
                                if (job.resources[resource_key] <
                                        job.used_resources[resource_key]):
                                    await instant
                                    job_execution.cancel()
                                    await instant
                            except KeyError:
                                # check is not relevant if the data is not stored
                                pass
                    # self.scheduler.update_drone(self)
                    await job_execution.done
            except ResourcesUnavailable:
                await instant
                job_execution.cancel()
                await instant
            except AssertionError:
                await instant
                job_execution.cancel()
                await instant
            self.jobs -= 1
            if job._cached_data:
                self.jobs_with_cached_data -= 1

            await self.scheduler.job_finished(job)
            self._utilisation = self._allocation = None
            self.scheduler.update_drone(self)
            await sampling_required.put(self)
            await sampling_required.put(
                DroneStatusCaching(
                    repr(self),
                    self.pool_resources["cores"],
                    self.theoretical_available_resources["cores"],
                    self.jobs_with_cached_data,
                ))