def run(self): """ @brief: This function overwrites the run function in song.py. """ global RUNNING RUNNING = True val = beating_heart.start_heartbeat(job_id=m_conf.i2_write_to_db_id) print "Starting loop..." done_param = 0 ins_tid = time.time() - 60.5 temperatures = "" while RUNNING: tid = time.time() if tid - ins_tid >= 60.: ins_tid = time.time() try: tmp_temp_set = i2_temp_contr.heat_controler().get_tset() except Exception, e: tmp_temp_set = 0 print clock.timename(), e try: tmp_temp_act = i2_temp_contr.heat_controler().get_tact() except Exception, e: tmp_temp_act = 0 print clock.timename(), e try: tmp_status = i2_temp_contr.heat_controler().get_status() except Exception, e: tmp_status = 0 print clock.timename(), e
def run(self): """ @brief: This function overwrites the Daemon function. While loop and connection end is in this function. """ global RUNNING RUNNING = True val = beating_heart.start_heartbeat(job_id=m_conf.spec_ccd_id) stamp = 0 try: server = SimpleXMLRPCServer( (spec_ccd_config.serverhost, spec_ccd_config.port), requestHandler=RequestHandler, logRequests=False) except Exception, e: print 'error: ', e stamp = 1
def run(self): """ """ done_param = 0 global RUNNING RUNNING = True val = beating_heart.start_heartbeat(job_id=m_conf.scheduler_id) strat = or_strategy.defStrat() i = 0 while RUNNING: strat.handle_next() # if int(float(time.strftime("%H", time.gmtime()))) >= 9 and int(float(time.strftime("%H", time.gmtime()))) <= 16: # time.sleep(scheduler_config.check_time_sleeping) # else: # time.sleep(scheduler_config.check_time) ### This should copy the content of the log file to old log file and clear it at 7 UTC. ## Moves nightly output til obs log. yesterday = datetime.datetime.now() - datetime.timedelta(days=1) folder_date = yesterday.strftime('%Y%m%d') output_log = "/home/obs/logs/scheduler_logs/" + str( folder_date) + "_obs.log" if int(float(time.strftime( "%H", time.gmtime()))) == 9 and done_param == 0: daily_logging_handler.handle_log_files( scheduler_config.outstream, output_log) done_param = 1 #sys.exit("%s The scheduler was automatically stopped..." % clock.timename()) if done_param == 1 and int( float(time.strftime("%H", time.gmtime()))) > 9: done_param = 0 if i % 1000 == 0: print clock.timename(), "The scheduler was alive" sys.stdout.flush() i += 1 time.sleep(scheduler_config.check_time)
def run(self): """ @brief: This function overwrites the run function in song.py. """ global RUNNING RUNNING = True val = beating_heart.start_heartbeat(job_id=m_conf.monitor_id) song_checker_handle = Check_something() if song_monitor_config.mon_telescope_info == 1: col_tel_info_thread_handle = thread.start_new_thread(song_checker_handle.collect_tel_info, ()) over_all_obs_state_thread_handle = thread.start_new_thread(song_checker_handle.over_all_obs_state, ()) monitor_runs_thread_handle = thread.start_new_thread(song_checker_handle.check_if_monitor_runs, ()) done_param = 0 self.telescope_hangs_sms = 0 global past_time past_time = time.time() print clock.timename(), " Starting handle_request loop..." while RUNNING: #### This checks if the loop is running. If it hangs somewhere a wakeup message will be sent out. past_time = time.time() if song_monitor_config.mon_time == 1: # If the config file specifies it time checks will be carried out. try: song_checker_handle.check_time() except Exception,e: print clock.timename(), " Problem in check_time()" print clock.timename(), e if song_monitor_config.mon_weather == 1: # If the config file specifies it weather checks will be carried out. try: song_checker_handle.check_weather() except Exception,e: print clock.timename(), " Problem in check_weather()" print clock.timename(), e
def run(self): """ @brief: This function overwrites the run function in song.py. """ global RUNNING RUNNING = True val = beating_heart.start_heartbeat(job_id=m_conf.daily_calib_id) exec_calibs = daily_calib.ACQ_CALIBS() done_log_param = 0 done_param = 0 done_isong_param = 0 focusing_done = 0 obs_sun_done = 0 calib_done_param = 0 m3_exercise_performed = 0 self.songwriter_email_send = 0 print "Starting loop at: ", clock.whattime() while RUNNING: # check if time of day is correct: sun_alt = sun_handle.sun_alt() if str(sun_alt)[0] == "-": sun_alt_d = float(str(sun_alt).split(":")[0]) - float( str(sun_alt).split(":")[1]) / 60.0 - float( str(sun_alt).split(":")[2]) / 3600.0 elif str(sun_alt)[0] != "-": sun_alt_d = float(str(sun_alt).split(":")[0]) + float( str(sun_alt).split(":")[1]) / 60.0 + float( str(sun_alt).split(":")[2]) / 3600.0 ################################# #### Get time to next sun set ### tmp_time_str2 = datetime.datetime.strptime( str(sun_handle.sun_set_next()), "%Y/%m/%d %H:%M:%S") time_diff = tmp_time_str2 - datetime.datetime.utcnow() hours_to_next_sun_set = int( time_diff.days) * 24. + time_diff.seconds / (24. * 3600.) * 24 #### Get time from previous sun set ### tmp_time_str2 = datetime.datetime.strptime( str(sun_handle.sun_set_pre()), "%Y/%m/%d %H:%M:%S") time_diff2 = datetime.datetime.utcnow() - tmp_time_str2 hours_from_pre_sun_set = int( time_diff2.days) * 24. + time_diff2.seconds / (24. * 3600.) * 24 ################################# #### Get time to next sun set ### tmp_time_str2 = datetime.datetime.strptime( str(sun_handle.sun_rise_next()), "%Y/%m/%d %H:%M:%S") time_diff = tmp_time_str2 - datetime.datetime.utcnow() hours_to_next_sun_rise = int( time_diff.days) * 24. + time_diff.seconds / (24. * 3600.) * 24 #### Get time from previous sun set ### tmp_time_str2 = datetime.datetime.strptime( str(sun_handle.sun_rise_pre()), "%Y/%m/%d %H:%M:%S") time_diff2 = datetime.datetime.utcnow() - tmp_time_str2 hours_from_pre_sun_rise = int( time_diff2.days) * 24. + time_diff2.seconds / (24. * 3600.) * 24 ################################# if daily_config.observe_sun == "yes" and obs_sun_done == 0 and int( datetime.datetime.utcnow().hour) > 14: # Check if dome is open: slit_state = gettsi.get_position_instrumental_dome_slit_currpos( sender="observer") if str(slit_state) != '1.0': print "The Monitor had not opened the dome yet!" else: if float(sun_alt_d) > float( 1.0 ) and hours_to_next_sun_set < 2.0 and hours_to_next_sun_set > 1.0: print "The time is right and the Sun observations will now be performed at: ", clock.obstimeUT( ) try: print os.system( "python /home/madsfa/subversion/trunk/obs_scripts/sky_observations.py" ) except Exception, e: print e print "Could not perform the Sun observations..." else: print "The Sun observation script is now done at : ", clock.obstimeUT( ) obs_sun_done = 1 ######## Weekly focusing the spectrograph: if float(time.strftime("%H", time.gmtime( ))) == daily_config.focus_at and time.strftime( "%a", time.gmtime() ) == daily_config.which_day_to_focus and focusing_done == 0 and daily_config.run_weekly_focus == "yes": print "Starting to run the focus sequence for the spectrograph at: ", clock.obstimeUT( ) ret_val = "" ret_val_focus = "" try: ret_val = focusing_spec.focus_the_spectrograph() except Exception, e: print e print "Could not acquire the spectres for focusing" ret_val = "fail" if ret_val == "done": try: ret_val_focus = focus_determination.main() except Exception, e: print e print "Could not calcullate the best focus value" if ret_val_focus != "": print "Focusing the spectrograph was completed at: ", clock.obstimeUT( ) print "The focus will be set to: ", str( int(round(ret_val_focus))) print os.system( "/home/obs/programs/DMC/pst.py move -m5 -p%s" % (str(int(round(ret_val_focus))))) tmp_file = open(m_conf.focus_val_file, "w") tmp_file.write(str(int(round(ret_val_focus)))) tmp_file.close()
def run(self): """ """ done_log_param = 0 global RUNNING RUNNING = True #self.selector = selector.SELECTOR() #self.insertor = insertor self.sun_handle = song_star_checker.sun_pos( site=m_conf.song_site) # Tenerife sun handle self.daily_update = 0 self.daily_sun_insert = 0 val = beating_heart.start_heartbeat(job_id=m_conf.conductor_id) over_all_obs_state = get_database_values(table_name='tel_dome', fields=['extra_param_1']) gc.disable() process = psutil.Process(os.getpid()) print("Memory used in percent : %0.3f" % float(process.memory_percent())) mem = process.memory_info() mem_old = (float(mem.vms) / float(2**20)) print "" print clock.timename(), "The Conductor was started!\n" print clock.timename( ), "The over all observing state was: ", over_all_obs_state[ 'extra_param_1'] while RUNNING: if int( float( datetime.datetime.strftime( datetime.datetime.utcnow(), "%H"))) < 9 and self.sun_handle.sun_alt( unit='f') < 0.0: yesterday = datetime.datetime.utcnow() - datetime.timedelta( days=1) folder_date = yesterday.strftime('%Y-%m-%d') else: folder_date = datetime.datetime.strftime( datetime.datetime.utcnow(), "%Y-%m-%d") # print "Checking the date: %s" % (str(folder_date)) ###################### DAY TIME CHECK ################################ if int( float( datetime.datetime.strftime( datetime.datetime.utcnow(), "%H"))) < 10 and self.sun_handle.sun_alt( unit='f') > 1.0: try: daytime_obs = check_daytime.Check_Daytime(folder_date) except Exception, e: print clock.timename(), e else: if daytime_obs == 0 and self.daily_sun_insert == 0: print clock.timename( ), "The Solar observations were not inserted yet. Will do now" try: #insertor.insert_solar_observations() insertor.insert_solar_observations_soda() except Exception, e: print clock.timename( ), "Did not call the check-for-gaps function" print clock.timename(), e else: self.daily_sun_insert = 1 if conf.check_for_timecritical == "yes" and self.daily_update == 0: st = datetime.datetime.utcnow() se = datetime.datetime.utcnow() + datetime.timedelta( days=1) try: selected_target = selector.SELECTOR().determine_next( timegap=[st, se], project_critical_type=["timecritical"]) except Exception, e: print clock.timename( ), "Problem in the selector.determine_next function..." print clock.timename(), e else: if selected_target != None: # Checking if they are already inserted: ids = [] names = [] for tmp_or in selected_target: ids.append(tmp_or[1]) names.append(tmp_or[2]) check_val = check_daytime.check_timecritical( folder_date, ids) if check_val == 0: for tcrit_target in selected_target: insertor.insert_timecritical_OR( pre_obs_spec_id=tcrit_target[1]) try: send_song_mail.send_mail( ).sending_an_email( reciever=["mads", "frank"], sender="SONG_MS", subject="Time critical OR inserted", message= "The conductor has inserted time critical OR(s) for the coming night.\nObject(s): %s\n" % str(names)) except Exception, e: print "Could not send e-mail on time critical insertion..."