tasks.py 1.28 KB
from __future__ import absolute_import

from celery.task import Task

from django.templatetags.static import static
import socket

import time

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 ...
            self.server_socket.accept()
            self.alert_received()

    def alert_received(self):
        # ici, 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()
        sequences = [sequence.strip('\n') for sequence in sequences]
        for sequence in sequences:
            pass

class change_obs_strategy(Task):

    def run(self):
        time.sleep(5)
        print("change_obs_strategy")