Blame view

src/core/pyros_django/scheduling/A_Scheduler.py 3.71 KB
6cd48351   Etienne Pallier   AgentScheduler is...
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/env python3

import sys
##import utils.Logger as L
#import threading #, multiprocessing, os
import time

#from django.db import transaction
#from common.models import Command

sys.path.append("..")
sys.path.append("../../../..")
b95a693f   Alexis Koralewski   restructuration d...
13
from src.core.pyros_django.majordome.agent.Agent import Agent, build_agent, log
6cd48351   Etienne Pallier   AgentScheduler is...
14
15

# PM 20190416 recycle code
a0dd0d01   Etienne Pallier   update agent sched
16
#from common.models import *
b95a693f   Alexis Koralewski   restructuration d...
17
from seq_submit.models import Sequence
6cd48351   Etienne Pallier   AgentScheduler is...
18
19
20
21
22

##log = L.setupLogger("AgentXTaskLogger", "AgentX")



23a61124   Alexis Koralewski   Change obsconfig ...
23
class A_Scheduler(Agent):
6cd48351   Etienne Pallier   AgentScheduler is...
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39


    # FOR TEST ONLY
    # Run this agent in simulator mode
    TEST_MODE = False
    # Run the assertion tests at the end
    TEST_WITH_FINAL_TEST = True
    TEST_MAX_DURATION_SEC = None
    #TEST_MAX_DURATION_SEC = 120

    # PM 20190416 fucking config path starting: /home/patrick/Dev/PYROS/start_agent.py agentM
    ##_path_data = 'config'
    _path_data = 'config/old_config'

    log.debug("PLC instanciated")

0bcd6dd5   Etienne Pallier   renamed Agent met...
40
    _AGENT_SPECIFIC_COMMANDS = [
bd4b900a   Etienne Pallier   update replan
41
        #"do_replan",
0bcd6dd5   Etienne Pallier   renamed Agent met...
42
        "do_stop_replan",
bd4b900a   Etienne Pallier   update replan
43
    ]
6cd48351   Etienne Pallier   AgentScheduler is...
44

6cd48351   Etienne Pallier   AgentScheduler is...
45
46
47
48
49
50
51
52
53
54
55
56
57
58

    """
    =================================================================
        FUNCTIONS RUN INSIDE MAIN THREAD
    =================================================================
    """
    # old config
    # @override
    #def __init__(self, name:str=None, config_filename=None, RUN_IN_THREAD=True):
    # def __init__(self, config_filename=None, RUN_IN_THREAD=True):
    #     ##if name is None: name = self.__class__.__name__
    #     super().__init__(config_filename, RUN_IN_THREAD)

    # new config (obsconfig)
8f3fbca4   Etienne Pallier   Simplified Agent,...
59
60
    #def __init__(self, name:str=None, RUN_IN_THREAD=True):
    def __init__(self, name:str=None):
6cd48351   Etienne Pallier   AgentScheduler is...
61
62
        if name is None:
            name = self.__class__.__name__
8f3fbca4   Etienne Pallier   Simplified Agent,...
63
64
        super().__init__()
        #super().__init__(RUN_IN_THREAD)
0bcd6dd5   Etienne Pallier   renamed Agent met...
65
    
6cd48351   Etienne Pallier   AgentScheduler is...
66
    # @override
0bcd6dd5   Etienne Pallier   renamed Agent met...
67
68
    def _init(self):
        super()._init()
6cd48351   Etienne Pallier   AgentScheduler is...
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
        log.debug("end init()")
        # --- Set the mode according the startmode value
        ##agent_alias = self.__class__.__name__
        ##self.set_mode_from_config(agent_alias)

    '''
    # @override
    def load_config(self):
        super().load_config()
    '''

    '''
    # @override
    def update_survey(self):
        super().update_survey()
    '''

    '''
    # @override
    def get_next_command(self):
        return super().get_next_command()
    '''

    # @override
    def do_log(self):
        super().do_log()

    def replan_sequences(self):
a0dd0d01   Etienne Pallier   update agent sched
97
        print("\n start of sequences (re-)planning...\n")
6cd48351   Etienne Pallier   AgentScheduler is...
98
        time.sleep(5)
a0dd0d01   Etienne Pallier   update agent sched
99
100
101
        sequences = Sequence.objects.filter(status="TBP")
        print("List of sequences to be planned :")
        for seq in sequences:
bd4b900a   Etienne Pallier   update replan
102
103
104
105
            print('-', seq.name, '('+seq.status+') :')
            print('-- albums : ', seq.albums.all())
            print('-- plans : ')
            for album in seq.albums.all():
ec67354c   Etienne Pallier   ajout de agentIma...
106
                print(album)
bd4b900a   Etienne Pallier   update replan
107
                for plan in album.plans.all():
ec67354c   Etienne Pallier   ajout de agentIma...
108
                    print('plan id', plan.id)
bd4b900a   Etienne Pallier   update replan
109

a0dd0d01   Etienne Pallier   update agent sched
110
        print("\n ...end of sequences (re-)planning\n")
6cd48351   Etienne Pallier   AgentScheduler is...
111
112
113

    # Note : called by _routine_process() in Agent
    # @override
547df0ef   Etienne Pallier   routine_process_b...
114
    def _routine_process_iter_start_body(self):
a0dd0d01   Etienne Pallier   update agent sched
115
        print("The Observatory configuration :")
c96e5f7e   Etienne Pallier   update AgentSched...
116
        self.show_config()
739c899f   Etienne Pallier   Ajout routine_pro...
117
118
119
120
121
        log.debug("in routine_process_before_body()")
        #self.replan_sequences()

    # Note : called by _routine_process() in Agent
    # @override
547df0ef   Etienne Pallier   routine_process_b...
122
    def _routine_process_iter_end_body(self):
739c899f   Etienne Pallier   Ajout routine_pro...
123
124
125
        print("The Observatory configuration :")
        #self.show_config()
        log.debug("in routine_process_after_body()")
6cd48351   Etienne Pallier   AgentScheduler is...
126
127
128
129
130
131
132
133
134
135
136
        self.replan_sequences()

    '''
    # @override
    def exec_specific_cmd_end(self, cmd:Command, from_thread=True):
        super().exec_specific_cmd_end(cmd, from_thread)
    '''


if __name__ == "__main__":

23a61124   Alexis Koralewski   Change obsconfig ...
137
    agent = build_agent(A_Scheduler)
6cd48351   Etienne Pallier   AgentScheduler is...
138
139
    print(agent)
    agent.run()