Blame view

pyros_django/majordome/TaskManager.py 1.61 KB
ddf59dd4   haribo   Remaniement :
1
from common.models import *
bb45cd4a   haribo   Date: 25/05/2016
2

9774228b   haribo   Date: 22/06/2016
3
import time
bb0fbab1   haribo   Fini de mettre la...
4
from devices import Telescope, CameraVIS, CameraNIR
bb45cd4a   haribo   Date: 25/05/2016
5

af5d8b11   Etienne Pallier   Nouveau shell pyr...
6

9774228b   haribo   Date: 22/06/2016
7
def delete_pending_tasks(task_names, terminate=False):
af5d8b11   Etienne Pallier   Nouveau shell pyr...
8
    """
bb45cd4a   haribo   Date: 25/05/2016
9
10
11
        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 
af5d8b11   Etienne Pallier   Nouveau shell pyr...
12
    """
bb45cd4a   haribo   Date: 25/05/2016
13

af5d8b11   Etienne Pallier   Nouveau shell pyr...
14
    # TODO : il faudra aller plus loin, et dire aux instruments de s'arrĂȘter
9774228b   haribo   Date: 22/06/2016
15

bb45cd4a   haribo   Date: 25/05/2016
16
17
18
19
    for task_name in task_names:
        tasks = TaskId.objects.filter(task=task_name)
        for task in tasks:
            print("je revoke : ", task.task_id)
af5d8b11   Etienne Pallier   Nouveau shell pyr...
20
            # TODO:
5e45ba9f   Etienne Pallier   Bye Bye Celery (f...
21
            ###revoke(task.task_id, terminate=terminate)
9774228b   haribo   Date: 22/06/2016
22
23
24
25
26
27
            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)

af5d8b11   Etienne Pallier   Nouveau shell pyr...
28

9774228b   haribo   Date: 22/06/2016
29
def delete_pending_routine():
af5d8b11   Etienne Pallier   Nouveau shell pyr...
30
    """
9774228b   haribo   Date: 22/06/2016
31
32
        It is called in case of a routine registered
        It deletes the pending execute_sequence
af5d8b11   Etienne Pallier   Nouveau shell pyr...
33
    """
9774228b   haribo   Date: 22/06/2016
34
35

    delete_pending_tasks(["execute_sequence"], terminate=False)
ddf59dd4   haribo   Remaniement :
36
    tel = Telescope.TelescopeController()
00fa2456   haribo   Debug adaption code
37
    tel.do("ABORT")
9774228b   haribo   Date: 22/06/2016
38
39
40


def delete_pending_alert():
af5d8b11   Etienne Pallier   Nouveau shell pyr...
41
    """
9774228b   haribo   Date: 22/06/2016
42
43
        It is called in case of an alert registered
        It deletes the pending execute_sequence, and the pending + executing plans
af5d8b11   Etienne Pallier   Nouveau shell pyr...
44
    """
9774228b   haribo   Date: 22/06/2016
45
46

    delete_pending_tasks(["execute_sequence"], terminate=False)
00fa2456   haribo   Debug adaption code
47
48
    delete_pending_tasks(["execute_plan"], terminate=False)

ddf59dd4   haribo   Remaniement :
49
    tel = Telescope.TelescopeController()
bb0fbab1   haribo   Fini de mettre la...
50
51
    VIScam = CameraVIS.VISCameraController()
    NIRcam = CameraNIR.NIRCameraController()
00fa2456   haribo   Debug adaption code
52
53
54
    tel.do("ABORT")
    VIScam.do("ABORT")
    NIRcam.do("ABORT")