AgentScheduler.py 3.4 KB
#!/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

import os
pwd = os.environ['PROJECT_ROOT_PATH']
if pwd not in sys.path:
    sys.path.append(pwd)
from src.core.pyros_django.majordome.agent.Agent import Agent, build_agent, log

# PM 20190416 recycle code
#from common.models import *
from seq_submit.models import Sequence

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



    '''
    # 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)
    def __init__(self, name:str=None):
        if name is None:
            name = self.__class__.__name__
        super().__init__()
    # @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):
        print("\n start of sequences (re-)planning...\n")
        time.sleep(5)
        sequences = Sequence.objects.filter(status="TBP")
        print("List of sequences to be planned :")
        for seq in sequences:
            print('-', seq.name, '('+seq.status+')')
            #print('-- with albums : ', seq.albums)
        print("\n ...end of sequences (re-)planning\n")

    # Note : called by _routine_process() in Agent
    # @override
    def routine_process_body(self):
        print("The Observatory configuration :")
        self.show_config()
        log.debug("in routine_process_body()")
        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()