Coverage for django_napse/simulations/tasks/simulation_queue.py: 31%
36 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-12 13:49 +0000
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-12 13:49 +0000
1from django_napse.core.tasks import BaseTask
2from django_napse.simulations.models import SimulationQueue
3from django_napse.utils.errors import SimulationError
6class SimulationQueueTask(BaseTask):
7 name = "simulation_queue"
8 interval_time = 5
9 time_limit = 60 * 60
10 soft_time_limit = 60 * 60
12 def run(self):
13 """Run TASK.
15 Process all pending Sims one by one.
16 """
17 if not self.avoid_overlap(verbose=True):
18 return
19 queue = SimulationQueue.objects.filter(error=False).order_by("created_at").first()
21 if queue is None:
22 return
23 if queue.status == "RUNNING":
24 return
25 try:
26 queue.run_quicksim()
27 queue = SimulationQueue.objects.get(simulation_reference=queue.simulation_reference)
28 except SimulationError.CancelledSimulationError:
29 print("BotSimQueueTask: cancelled")
30 queue.delete()
31 return
32 except Exception as e:
33 print("BotSimQueueTask: error")
34 print(str(e))
35 queue.error = True
36 queue.save()
37 raise e
39 if queue.is_finished():
40 print("BotSimQueueTask: finished")
41 queue.delete()
42 else:
43 error_msg = f"SimQueueTask: {queue} status {queue.status} completion {queue.completion}"
44 raise SimulationError.BotSimQueueError(error_msg)
47SimulationQueueTask().delete_task()
48SimulationQueueTask().register_task()