from __future__ import absolute_import from celery.task import Task from common.RequestBuilder import RequestBuilder from django.templatetags.static import static import socket from pyrosapp.models import Request, Sequence, Log import time from celery.utils.timer2 import Timer import os, shutil import observation_manager IP = '127.0.0.1' PORT = 31569 class alert_listener(Task): ''' Launched at server start Listens to VOEvents, and create appropriate request when an event is received ''' def run(self): print("run") self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.server_socket.setblocking(True) self.server_socket.bind((IP, PORT)) self.server_socket.listen(12) while True: #il faudra que tout ça soit dans un try ... print("Task en attente de signal") self.server_socket.accept() print("signal reçu") self.alert_received() def alert_received(self): # je supprime les sequences et requetes déjà existantes Sequence.objects.all().delete() Request.objects.all().delete() Log.objects.create(agent='Alert manager', message='Alert received') for file_name in os.listdir(observation_manager.tasks.IMAGES_FOLDER): if file_name != "empty": file_path = os.path.join(observation_manager.tasks.IMAGES_FOLDER, file_name) os.unlink(file_path) # j'ouvre le fichier des séquences de simulation, et j le lis ligne par ligne with open("alert_manager/simulation_sequences", 'r') as sequences_file: sequences = sequences_file.readlines() Log.objects.create(agent='Alert manager', message='Simulation sequences file read') sequences = [sequence.strip('\n') for sequence in sequences] request_builder = RequestBuilder() request_builder.start_new_request() for sequence in sequences: request_builder.add_sequence(sequence) request_builder.validate_request() Log.objects.create(agent='Alert manager', message='Request built') class change_obs_strategy(Task): def run(self): time.sleep(5) print("change_obs_strategy")