Blame view

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

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

9774228b   haribo   Date: 22/06/2016
7
def delete_pending_tasks(task_names, terminate=False):
bb45cd4a   haribo   Date: 25/05/2016
8
9
10
11
12
13
    '''
        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 
    '''

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

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)
9774228b   haribo   Date: 22/06/2016
20
21
22
23
24
25
26
27
28
29
30
31
32
33
            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)
ddf59dd4   haribo   Remaniement :
34
    tel = Telescope.TelescopeController()
00fa2456   haribo   Debug adaption code
35
    tel.do("ABORT")
9774228b   haribo   Date: 22/06/2016
36
37
38
39
40
41
42
43
44


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)
00fa2456   haribo   Debug adaption code
45
46
    delete_pending_tasks(["execute_plan"], terminate=False)

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