TaskManager.py
1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from common.models import *
import time
from devices import Telescope, CameraVIS, CameraNIR
def delete_pending_tasks(task_names, terminate=False):
"""
Deletes the pending tasks given in task_names, getting their ids in DB.
Removes them from db.
:param task_names: array of tasks names to delete
"""
# TODO : il faudra aller plus loin, et dire aux instruments de s'arrĂȘter
for task_name in task_names:
tasks = TaskId.objects.filter(task=task_name)
for task in tasks:
print("je revoke : ", task.task_id)
# TODO:
###revoke(task.task_id, terminate=terminate)
task.delete()
""" The sleep is in case of sequence stopping :
if it was creating a plan_exec, the creation must be finished before we try to delete it """
time.sleep(1)
def delete_pending_routine():
"""
It is called in case of a routine registered
It deletes the pending execute_sequence
"""
delete_pending_tasks(["execute_sequence"], terminate=False)
tel = Telescope.TelescopeController()
tel.do("ABORT")
def delete_pending_alert():
"""
It is called in case of an alert registered
It deletes the pending execute_sequence, and the pending + executing plans
"""
delete_pending_tasks(["execute_sequence"], terminate=False)
delete_pending_tasks(["execute_plan"], terminate=False)
tel = Telescope.TelescopeController()
VIScam = CameraVIS.VISCameraController()
NIRcam = CameraNIR.NIRCameraController()
tel.do("ABORT")
VIScam.do("ABORT")
NIRcam.do("ABORT")