Commit d5611ba18b7d1bf09e5bdef5730812902f278013

Authored by Jeremy
1 parent 2d95ba4e
Exists in master and in 1 other branch dev

Routine simulator structure implemented

pyrosrun.sh
... ... @@ -12,7 +12,9 @@ COMMANDS="\n
12 12 \t'start' : Starts the simulators then the celery workers, then the web server\n
13 13 \t'stop' : Stops the celery workers then the simulators\n
14 14 \t'clean_logs' : Clear all pyros .log files from /logs\n
15   -\t'simulator' : Launch routine simulator\n"
  15 +\t'simulator' : Launch routine simulator\n
  16 +\t'kill_simulation : Kill web server and celery tasks (only use during simulation)'\n
  17 +\t'sim : start only simulation task'"
16 18 #\t'test_runserver' : Launch web server on test database
17 19  
18 20 NEEDED_COMMAND="One command is needed. Possible commands : $COMMANDS"
... ... @@ -89,6 +91,9 @@ case "$1" in
89 91 "kill_simulation")
90 92 scripts/kill_simulation.sh
91 93 ;;
  94 + "sim")
  95 + celery worker -A pyros -Q simulator_q -n pyros@simulator -c 1 &
  96 + ;;
92 97 *)
93 98 echo -e $INVALID_COMMAND
94 99 ;;
... ...
src/pyros/settings.py
... ... @@ -121,8 +121,8 @@ LOGIN_URL = "/"
121 121  
122 122 CELERY_TEST = False
123 123  
124   -if CELERY_TEST == False:
125   - if MYSQL == False:
  124 +if not CELERY_TEST:
  125 + if not MYSQL:
126 126 DATABASES = {
127 127 'default': {
128 128 'ENGINE': 'django.db.backends.sqlite3',
... ...
src/simulator/tasks.py
... ... @@ -10,7 +10,60 @@ import time
10 10  
11 11 log = l.setupLogger("simulator", "simulator")
12 12  
  13 +class SimulatorRoutines():
  14 + def __init__(self, quantity, dtime):
  15 + self.quantity = quantity
  16 + self.dtime = dtime
  17 + log.info("SimulatorRoutines class instantiated with %d routines to be executed with an interval of time %d"%(quantity,dtime))
  18 +
  19 + # First create some scientific programs
  20 + def createScientificPrograms(self):
  21 + pass
  22 +
  23 + # create some user levels with diferent priorities
  24 + def createUserLevels(self):
  25 + pass
  26 +
  27 + # create some pyros users
  28 + def createPyrosUsers(self, country, user_id, user_level_id):
  29 + pass
  30 +
  31 + # create auth users
  32 + def createAuthUsers(self):
  33 +
  34 + # You can now create Requests
  35 + def createRequest(self, pyros_user_id, scientific_program_id):
  36 + pass
  37 +
  38 + # requests must have sequences
  39 + def createSequences(self, request):
  40 + pass
  41 +
  42 + # Sequences must have albums
  43 + def createAlbums(self, sequence):
  44 + pass
  45 +
  46 + # albums must have plans
  47 + def createPlans(self, album):
  48 + pass
  49 +
  50 + def process(self):
  51 + pass
  52 +
  53 +
13 54 class simulator(Task):
  55 + shouldClean = False
  56 +
14 57 def run(self):
15   - log.info("Simulator run function")
16   - os.system("%s/../pyrosrun.sh kill_simulation"%settings.BASE_DIR)
  58 + simu = SimulatorRoutines(100, 2)
  59 + # for schedule in py_schedules:
  60 +
  61 +
  62 + # END OF EXECTUION (KILLING WEB SERVER AN PROCESS)
  63 + if (self.shouldClean == True):
  64 + os.system("%s/../pyrosrun.sh kill_simulation"%settings.BASE_DIR)
  65 +
  66 +if __name__ == "__main__":
  67 + sim = simulator(Task)
  68 + sim.shouldClean = False
  69 + sim.run()
... ...