def poll(self, conf_tree): """Poll for prerequisites of applications.""" # Get the poll configuration. poll_test, poll_file_test, poll_all_files, poll_any_files = ( self._get_tests(conf_tree)) poll_delays = [] if poll_test or poll_all_files or poll_any_files: poll_delays = self._get_delays(conf_tree) # Launch the polling. t_init = get_timepoint_for_now() poll_test, poll_any_files, poll_all_files = (self._run_poll( poll_test, poll_all_files, poll_any_files, poll_delays, poll_file_test=poll_file_test)) t_finish = get_timepoint_for_now() # Handle any failures. failed_items = [] if poll_test: failed_items.append("test") if poll_any_files: failed_items.append("any-files") if poll_all_files: failed_items.append("all-files:" + self.popen.list_to_shell_str(poll_all_files)) if failed_items: now = get_timepoint_for_now() raise PollTimeoutError(now, t_finish - t_init, failed_items)
async def set_recurring_message(recur_string, channel, msg): recurrence = TimeRecurrenceParser().parse(recur_string) now = get_timepoint_for_now() when_time = get_next_after(recurrence, now) if when_time is not None: delay = float(when_time.get( "seconds_since_unix_epoch")) - datetime.datetime.now().timestamp() loop = asyncio.get_event_loop() loop.call_later( delay, lambda: loop.create_task( send_recurring_message(recur_string, channel, msg)))
def date_parse(self, time_point_str=None): """Parse time_point_str. Return (t, format) where t is a metomi.isodatetime.data.TimePoint object and format is the format that matches time_point_str. time_point_str -- The time point string to parse. Otherwise, use ref time. """ if time_point_str is None or time_point_str == self.STR_REF: time_point_str = self.ref_point_str if time_point_str is None or time_point_str == self.STR_NOW: time_point = get_timepoint_for_now() time_point.set_time_zone_to_local() if self.utc_mode or time_point.get_time_zone_utc(): # is in UTC parse_format = self.CURRENT_TIME_DUMP_FORMAT_Z else: parse_format = self.CURRENT_TIME_DUMP_FORMAT elif self.custom_parse_format is not None: parse_format = self.custom_parse_format time_point = self.strptime(time_point_str, parse_format) else: parse_formats = list(self.parse_formats) time_point = None while parse_formats: parse_format, should_use_datetime = parse_formats.pop(0) try: if should_use_datetime: time_point = self.get_datetime_strptime( time_point_str, parse_format) else: time_point = self.time_point_parser.strptime( time_point_str, parse_format) break except ValueError: pass if time_point is None: time_point = self.time_point_parser.parse( time_point_str, dump_as_parsed=True) parse_format = time_point.dump_format if self.utc_mode: time_point.set_time_zone_to_utc() return time_point, parse_format