Esempio n. 1
0
def check_delay_time(operation, delay_minutes=None, time=None, write=False):
    #
    # For a given operation, check if the delay has passed, or if it is time to execute it
    #
    # Input arguments: operation= is one of the foreseen operations ('sync_data', 'sync_db')
    #                  delay= is the delay - in minutes - between two executions
    #                  time= is the time (hh:mm) of the day for the execution
    #
    #                  write: if set, does write the ,info file
    #
    logger.debug("Entering routine %s" % 'check_delay_time')

    to_be_executed = False
    dir_info = es_constants.pid_file_dir
    operations_info_file = dir_info + os.path.sep + operation + '_execution.info'

    # If write option set, write the info and exit
    if write:
        info = {'latest_exec_time': datetime.datetime.now()}
        functions.dump_obj_to_pickle(info, operations_info_file)

    # Distinguish between delay/time
    if delay_minutes is not None:

        # Read info from the pickle object
        info = functions.load_obj_from_pickle(operations_info_file)
        if info is None:
            logger.debug("Operation %s not yet executed: execute it." %
                         operation)
            to_be_executed = True
        else:
            time_latest_execution = info['latest_exec_time']
            current_delta = datetime.datetime.now() - time_latest_execution
            current_delta_minutes = int(current_delta.seconds / 60)
            if current_delta_minutes > float(delay_minutes):
                to_be_executed = True

    elif time is not None:
        # Time to indicate
        if time == '99:99':
            to_be_executed = True
        else:
            now = datetime.datetime.now()
            if now.hour == int(time[0:2]) and now.minute == int(time[3:5]):
                to_be_executed = True
    else:
        logger.warning("Either delay_minutes or time has to be defined!")

    return to_be_executed
Esempio n. 2
0
def check_delay_time(operation, delay_minutes=None, time=None):

# For a given operation, check if the delay has passed, or if it is time to execute it
#
# Input arguments: operation= is one of the foreseen operations ('sync_data', 'sync_db')
#                  delay= is the delay - in minutes - between two executions
#                  time= is the time (hh:mm) of the day for the execution
#
    logger.debug("Entering routine %s" % 'check_delay_time')

    to_be_executed = False
    # Distinguish between delay/time
    if delay_minutes is not None:
        dir_info=es_constants.pid_file_dir
        operations_info_file=dir_info+os.path.sep+operation+'_execution.info'

        # Read info from the pickle object
        info = functions.load_obj_from_pickle()
        if info is None:
           logger.debug("Operation %s not yet executed: execute it." % operation)
           to_be_executed=True
        else:
            time_latest_execution = info.latest_exec_time
            current_delta=datetime.datetime.now()-time_latest_execution
            current_delta_minutes=int(current_delta.seconds/60)
            if current_delta_minutes > delay_minutes:
               to_be_executed=True

    elif time is not None:
        now=datetime.datetime.now()
        if now.minute==int(time[3:5]) and now.minute==int(time[3:5]):
           to_be_executed=True
    else:
       logger.warning("Either delay_minutes or time has to be defined!")

    return to_be_executed
Esempio n. 3
0
def get_eumetcast_info(eumetcast_id):

    filename = es_constants.get_eumetcast_processed_list_prefix + str(
        eumetcast_id) + '.info'
    info = functions.load_obj_from_pickle(filename)
    return info
Esempio n. 4
0
def get_eumetcast_info(eumetcast_id):

    filename = es_constants.get_eumetcast_processed_list_prefix+str(eumetcast_id)+'.info'
    info = functions.load_obj_from_pickle(filename)
    return info
Esempio n. 5
0
 def test_load_obj_from_pickle(self):
     functions.dump_obj_to_pickle(self.processed_info,
                                  self.processed_info_filename)
     result = functions.load_obj_from_pickle(self.processed_info_filename)
     self.assertEqual(result, self.processed_info)
Esempio n. 6
0
 def test_dump_obj_to_pickle(self):
     # logger.info('Pickle filename is: %s', self.processed_info_filename)
     functions.dump_obj_to_pickle(self.processed_info,
                                  self.processed_info_filename)
     result = functions.load_obj_from_pickle(self.processed_info_filename)
     self.assertEqual(result, self.processed_info)