Blame view

src/core/pyros_django/scheduler/AgentScheduler.py 4 KB
6cd48351   Etienne Pallier   AgentScheduler is...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/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("../../../..")
from src.core.pyros_django.agent.Agent import Agent, build_agent, log

# PM 20190416 recycle code
a0dd0d01   Etienne Pallier   update agent sched
16
17
#from common.models import *
from common.models import Sequence
6cd48351   Etienne Pallier   AgentScheduler is...
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

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



class AgentScheduler(Agent):


    # 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")

bd4b900a   Etienne Pallier   update replan
40
41
42
43
    AGENT_SPECIFIC_COMMANDS = [
        #"do_replan",
        #"do_stop_replan",
    ]
6cd48351   Etienne Pallier   AgentScheduler is...
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

    '''
    # Who should I send commands to ?
    #TEST_COMMANDS_DEST = "myself"
    TEST_COMMANDS_DEST = "AgentA"
    # Scenario to be executed
    TEST_COMMANDS_LIST = [
        "go_active",
        "go_idle",
        "go_active",
        "go_idle",
        "go_active",
        "go_idle",
        "exit",
    ]
    '''

    """
    =================================================================
        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,...
74
75
    #def __init__(self, name:str=None, RUN_IN_THREAD=True):
    def __init__(self, name:str=None):
6cd48351   Etienne Pallier   AgentScheduler is...
76
77
        if name is None:
            name = self.__class__.__name__
8f3fbca4   Etienne Pallier   Simplified Agent,...
78
79
        super().__init__()
        #super().__init__(RUN_IN_THREAD)
6cd48351   Etienne Pallier   AgentScheduler is...
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
    # @override
    def init(self):
        super().init()
        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
111
        print("\n start of sequences (re-)planning...\n")
6cd48351   Etienne Pallier   AgentScheduler is...
112
        time.sleep(5)
a0dd0d01   Etienne Pallier   update agent sched
113
114
115
        sequences = Sequence.objects.filter(status="TBP")
        print("List of sequences to be planned :")
        for seq in sequences:
bd4b900a   Etienne Pallier   update replan
116
117
118
119
            print('-', seq.name, '('+seq.status+') :')
            print('-- albums : ', seq.albums.all())
            print('-- plans : ')
            for album in seq.albums.all():
ec67354c   Etienne Pallier   ajout de agentIma...
120
                print(album)
bd4b900a   Etienne Pallier   update replan
121
                for plan in album.plans.all():
ec67354c   Etienne Pallier   ajout de agentIma...
122
                    print('plan id', plan.id)
bd4b900a   Etienne Pallier   update replan
123

a0dd0d01   Etienne Pallier   update agent sched
124
        print("\n ...end of sequences (re-)planning\n")
6cd48351   Etienne Pallier   AgentScheduler is...
125
126
127

    # Note : called by _routine_process() in Agent
    # @override
739c899f   Etienne Pallier   Ajout routine_pro...
128
    def routine_process_before_body(self):
a0dd0d01   Etienne Pallier   update agent sched
129
        print("The Observatory configuration :")
c96e5f7e   Etienne Pallier   update AgentSched...
130
        self.show_config()
739c899f   Etienne Pallier   Ajout routine_pro...
131
132
133
134
135
136
137
138
139
        log.debug("in routine_process_before_body()")
        #self.replan_sequences()

    # Note : called by _routine_process() in Agent
    # @override
    def routine_process_after_body(self):
        print("The Observatory configuration :")
        #self.show_config()
        log.debug("in routine_process_after_body()")
6cd48351   Etienne Pallier   AgentScheduler is...
140
141
142
143
144
145
146
147
148
149
150
151
152
153
        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__":

    agent = build_agent(AgentScheduler)
    print(agent)
    agent.run()