def shedule(self): now = tool.today(self._timezone) session_key = tool.session_key(self._session_period) try: yield self._inspect_session_date((now, session_key)) except Exception as e: logger.error(u'Exception was raised on session inspection: {}'.format(e.message), exc_info=1) return yield self._process_session((now, session_key)) yield self._process_sinks((now, session_key))
def get_queryset(self): tags = self.request.query_params.get('tags', None) start_time = self.request.query_params.get('start_time', None) end_time = self.request.query_params.get('end_time', None) if start_time and end_time: start_time = get_utctime(start_time) end_time = get_utctime(end_time) else: # default data of 1 day end_time = today() start_time = last_day() return MysqlStatHis.objects.filter( tags=tags, check_time__gte=start_time, check_time__lte=end_time).order_by('check_time')
def close_session(self, session_pair, autocommit=True): utc_session_date = session_pair[0].astimezone( pytz.timezone('UTC')).strftime('%Y-%m-%d %H:%M:%S') utc_now = tool.today('UTC').strftime('%Y-%m-%d %H:%M:%S') is_successfully = True try: self._connection.execute( u'''INSERT OR REPLACE INTO Sessions (Session, Opened, Closed) VALUES (:session, :opened, :closed)''', { u'session': session_pair[1], u'opened': utc_session_date, u'closed': u'' }) except Exception as e: logger.error( u'Exception was raised on close a session at {:%Y-%m-%d} {} #1: {}' .format(session_pair[0], session_pair[1], e.message)) self._connection.rollback() is_successfully = False try: self._connection.execute( u''' UPDATE Sessions SET Closed = :closed WHERE Session = :session AND Opened <= :opened AND Closed = "" ''', { u'session': session_pair[1], u'opened': utc_session_date, u'closed': utc_now }) except Exception as e: logger.error( u'Exception was raised on close a session at {:%Y-%m-%d} {} #2: {}' .format(session_pair[0], session_pair[1], e.message)) self._connection.rollback() is_successfully = False if is_successfully and autocommit: self._connection.commit() return is_successfully
def fetch_sinks(self): now = tool.today(self._timezone) fetch_array = [] for sink_item in self._sinks: array_item = {'measure': sink_item.name, 'data': []} if isinstance(sink_item, (sinks.TaskSinkGroup, sinks.TaskSinkChain, sinks.TaskSinkIndividual)): array_item['data'].extend(sink_item.get_data_sequence(now, self._timezone)) else: continue fetch_array.append(array_item) return fetch_array