async def get_total_area(self, request_objects): now1 = datetime.now() tt1 = now1.time() print('get_total_area_start', tt1) query = select([func.count(province.c.name)]). \ select_from(subdistrict_zipcode.join(subdistrict). join(district). join(city). join(province)) query = self._filter(query, request_objects) with self._tracer.start_span('start_get_total_area') as span: try: data = await self.db().execute(query) now2 = datetime.now() tt2 = now2.time() print('get_total_area_end', tt2) str_time = get_result_subtraction_time(tt1, tt2) span.log_kv({'process_time': str_time}) span.set_tag('query', query) span.set_tag('param', request_objects) except Exception as e: span.set_tag('error', e) data = e return data
async def get_subdistrict_by_zipcode(self, zipcode): now1 = datetime.now() tt1 = now1.time() print('get_subdistrict_by_zipcode_start', tt1) query = select([subdistrict.c.name]).select_from(subdistrict.join(subdistrict_zipcode)) \ .where(subdistrict_zipcode.c.zip_code == zipcode) with self._tracer.start_span( 'start_get_subdistrict_by_zipcode') as span: try: data = await self.db().fetch_all(query) now2 = datetime.now() tt2 = now2.time() print('get_subdistrict_by_zipcode_end', tt2) str_time = get_result_subtraction_time(tt1, tt2) span.log_kv({'process_time': str_time}) span.set_tag('query', query) span.set_tag('zipcode', zipcode) except Exception as e: span.set_tag('error', e) data = e return data
async def get_all_area(self, request_objects): now1 = datetime.now() tt1 = now1.time() print('get_all_area_start', tt1) query = select([province.c.name.label('province'), city.c.name.label('city'), city.c.type, district.c.name.label('district'), subdistrict.c.name.label('subdistrict'), subdistrict_zipcode.c.zip_code]).\ select_from(subdistrict_zipcode.join(subdistrict). join(district). join(city). join(province)) query = self._filter(query, request_objects) query = query.order_by(asc(province.c.name), asc(city.c.name)).\ limit(request_objects.limit).offset(request_objects.offset) with self._tracer.start_span('start_get_all_area') as span: try: data = await self.db().fetch_all(query) now2 = datetime.now() tt2 = now2.time() print('get_all_area_end', tt2) str_time = get_result_subtraction_time(tt1, tt2) span.log_kv({'process_time': str_time}) span.set_tag('query', query) span.set_tag('param', request_objects) except Exception as e: span.set_tag('error', e) data = e return data
async def fetch_aio(session, url, headers, timeout, tracer): now1 = datetime.now() tt1 = now1.time() print(url, tt1) with tracer.start_span(url) as span: async with session.get(url, headers=headers, timeout=timeout) as response: res = await response.json() now2 = datetime.now() tt2 = now2.time() str_time = get_result_subtraction_time(tt1, tt2) span.log_kv({'process_time': str_time}) span.set_tag('url', url) print(url, tt2) return res
async def get_by_id(self, id): now1 = datetime.now() tt1 = now1.time() print('get_by_id_start', tt1) query = expeditions.select().where('id' == id) with self._tracer.start_span('start_get_total_expedition') as span: try: data = await self.db().fetch_one(query) now2 = datetime.now() tt2 = now2.time() print('get_by_id_end', tt2) str_time = get_result_subtraction_time(tt1, tt2) span.log_kv({'process_time': str_time}) span.set_tag('query', query) span.set_tag('id', id) except Exception as e: span.set_tag('error', e) data = e return data
async def get_total(self, request_objects): now1 = datetime.now() tt1 = now1.time() print('get_total_start', tt1) query = select([func.count()]).select_from(expeditions) with self._tracer.start_span('start_get_total_expedition') as span: try: data = await self.db().execute(query) now2 = datetime.now() tt2 = now2.time() print('get_total_end', tt2) str_time = get_result_subtraction_time(tt1, tt2) span.log_kv({'process_time': str_time}) span.set_tag('query', query) span.set_tag('param', request_objects) except Exception as e: span.set_tag('error', e) data = e return data
async def get_all(self, request_objects): now1 = datetime.now() tt1 = now1.time() print('get_all_start', tt1) query = select([expeditions]).limit(10).offset(0) with self._tracer.start_span('start_get_all_expedition') as span: try: data = await self.db().fetch_all(query) now2 = datetime.now() tt2 = now2.time() print('get_all_end', tt2) str_time = get_result_subtraction_time(tt1, tt2) span.log_kv({'process_time': str_time}) span.set_tag('query', query) span.set_tag('param', request_objects) except Exception as e: span.set_tag('error', e) data = e return data