def handle(self, *args, **options): user = DimUser.objects.get_or_create(username="******")[0] sim_group = SimulationGroup(submitted_by=user) sim_group.save() print "Simulation group %s has been created successfully" % sim_group.id with open(os.path.join("ts_om","management", "commands", "default.xml")) as fp: xml = fp.read() simulation1 = add_simulation(sim_group, xml) print "Simulation %s has been created successfully" % simulation1.id simulation2 = add_simulation(sim_group, xml) print "Simulation %s has been created successfully" % simulation2.id dispatcher.submit(sim_group) print "Simulation group has been submitted successfully. Waiting for the results." seconds = 0 print sim_status.SCRIPT_DONE while simulation1.status != sim_status.SCRIPT_DONE and \ simulation1.status != sim_status.SCRIPT_ERROR and \ simulation1.status != sim_status.OUTPUT_ERROR: time.sleep(1) seconds += 1 if divmod(seconds, 60): print "Waiting %s seconds, status %s/%s" % (seconds, simulation1.status, simulation2.status) # reload model from the database simulation1 = Simulation.objects.get(id = simulation1.id) simulation2 = Simulation.objects.get(id = simulation2.id) print "Simulation result: %s/%s" % (simulation1.status, simulation2.status)
def submit(request, model, scenario_id): dim_user = DimUser.objects.get(username=request.user.username) scenario = Scenario.objects.get(id=scenario_id) simulation = scenario.simulation simulation_group = simulation.group # Check if this is the right user for this scenario if scenario.user != dim_user: raise PermissionDenied dispatcher.submit(simulation_group)
def submit_group(user, xml_scenarios, version=None): # Create Simulation and SimulationGroup if isinstance(user, User): user = DimUser.objects.get_or_create(username=user.username)[0] if isinstance(user, (str, unicode)): user = DimUser.objects.get_or_create(username=user)[0] sim_group = SimulationGroup(submitted_by=user) sim_group.save() for scenario in xml_scenarios: add_simulation(sim_group, scenario, version=version) try: dispatcher.submit(sim_group) return sim_group except RuntimeError: return None