def test_no_last_error_on_successful_event(self): global_sender = sender.get_global_sender() event.Event('unfollow', { 'from': 'userC', 'to': 'userD' }) self.assertEqual(global_sender.last_error, None) sender.close()
def test_emit_after_close(self): with self._sender as sender: self.assertTrue(sender.emit("blah", {"a": "123"})) sender.close() self.assertFalse(sender.emit("blah", {"a": "456"})) data = self._server.get_received() self.assertEqual(len(data), 1) self.assertEqual(data[0][2]["a"], "123")
def run(): max_retries = 7 retries = 0 today = datetime.today().strftime("%Y%m%d") while True: try: if retries >= max_retries: print(today, '-> Data.go.kr API Call Error!!!') return hira_url = 'http://apis.data.go.kr/B551182/hospInfoService/getHospBasisList' ServiceKey = '2UWvNIvNmrdJQKq4OhO3sipd2S7NO36m1bCqJi61wdShwJIp1Wg5D%2FAEanZ97vZAydIS%2FN9eL418xqyN7J0vzw%3D%3D' queryParams = '?' + 'serviceKey=' + ServiceKey + '&_type=json&numOfRows=10' # queryParams = '?numOfRows=70000&pageNo=1&ServiceKey=%s&_type=json'%(service_key) request = Request(hira_url + queryParams) request.get_method = lambda: 'GET' response = urlopen(request) if response.getcode( ) == 200: #urllib.request.urlopen().getcode() 의 결과값 status: 200 이면 잘 연결되었다는 뜻 response_body = urlopen(request).read() hosp_json_rt = response_body.decode('utf-8') hosp_items = json.loads(hosp_json_rt) print(today, '-> 병원 API호출통해 받은 건수 : ', hosp_items['response']['body']['totalCount']) else: print(today, '-> 병원 API호출 result : ', response.getcode()) retries += 1 wait = 2**(retries - 1) time.sleep(wait) continue sender.setup('td.hira', host='localhost', port=24224) print(today, '-> sender.setup ok ') tot = 0 #컬럼 제한 했으니 제한 없게 for item in hosp_items['response']['body']['items']['item']: tot = tot + 1 item['inputDate'] = today item['inputType'] = '병원' event.Event('getParmacyBasisList_getHospBasisList', item) if tot % 5000 == 0: print(today, '-> TD 전송 병원진행건수 : ', tot) print(today, '-> TD 전송 병원완료건수 : ', tot) sender.close() break except: retries += 1 wait = 2**(retries - 1) time.sleep(wait)
def main(): initial_energy = 30_000 colony = Colony([], initial_energy) while colony.is_active(): time.sleep(random.uniform(0.001, 0.01)) colony.new_day() print( f"A colony live {colony.days_alive} days with {initial_energy} energy") print( f"{colony.left} leaved, {colony.born} born and {colony.died} flies died during colony life" ) sender.close()
def test_failure_to_connect(self): self._server.close() with self._sender as sender: sender._send_internal(b"123") self.assertEqual(sender.pendings, b"123") self.assertIsNone(sender.socket) sender._send_internal(b"456") self.assertEqual(sender.pendings, b"123456") self.assertIsNone(sender.socket) sender.pendings = None overflows = [] def boh(buf): overflows.append(buf) def boh_with_error(buf): raise RuntimeError sender.buffer_overflow_handler = boh sender._send_internal(b"0" * sender.bufmax) self.assertFalse(overflows) # No overflow sender._send_internal(b"1") self.assertTrue(overflows) self.assertEqual(overflows.pop(0), b"0" * sender.bufmax + b"1") sender.buffer_overflow_handler = None sender._send_internal(b"0" * sender.bufmax) sender._send_internal(b"1") self.assertIsNone(sender.pendings) sender.buffer_overflow_handler = boh_with_error sender._send_internal(b"0" * sender.bufmax) sender._send_internal(b"1") self.assertIsNone(sender.pendings) sender._send_internal(b"1") self.assertFalse(overflows) # No overflow self.assertEqual(sender.pendings, b"1") self.assertIsNone(sender.socket) sender.buffer_overflow_handler = boh sender.close() self.assertEqual(overflows.pop(0), b"1")
def tearDown(self): from fluent.sender import _set_global_sender sender.close() _set_global_sender(None)
def run(): max_retries = 7 retries = 0 today = datetime.today().strftime("%Y%m%d") while True: try: if retries >= max_retries: print(today, '-> Data.go.kr API Call Error!!!') return url = 'http://apis.data.go.kr/B551182/pharmacyInfoService/getParmacyBasisList' queryParams = '?' + 'serviceKey=' + '0iL736RveVYyQp%2F99eV2vwEyvArFlIW4cPcPfSZd7sRb0tDE3wbwQTZrmZt3mxB55AOU9HQC3uiA6e%2F8oqt%2FCQ%3D%3D&_type=json&numOfRows=100000' request = Request(url + queryParams) request.get_method = lambda: 'GET' response = urlopen(request) if response.getcode() == 200: response_body = response.read() pharm_json_rt = response_body.decode('utf-8') pharm_items = json.loads(pharm_json_rt) print(today, '-> 약국 API호출통해 받은 건수 : ', pharm_items['response']['body']['totalCount']) else: print(today, '-> 약국 API호출 result : ', response.getcode()) retries += 1 wait = 2**(retries - 1) time.sleep(wait) continue url = 'http://apis.data.go.kr/B551182/hospInfoService/getHospBasisList' queryParams = '?' + 'serviceKey=' + '0iL736RveVYyQp%2F99eV2vwEyvArFlIW4cPcPfSZd7sRb0tDE3wbwQTZrmZt3mxB55AOU9HQC3uiA6e%2F8oqt%2FCQ%3D%3D&_type=json&numOfRows=100000' request = Request(url + queryParams) request.get_method = lambda: 'GET' response = urlopen(request) if response.getcode() == 200: response_body = urlopen(request).read() hosp_json_rt = response_body.decode('utf-8') hosp_items = json.loads(hosp_json_rt) print(today, '-> 병원 API호출통해 받은 건수 : ', hosp_items['response']['body']['totalCount']) else: print(today, '-> 병원 API호출 result : ', response.getcode()) retries += 1 wait = 2**(retries - 1) time.sleep(wait) continue sender.setup('td.hira', host='localhost', port=24224) print(today, '-> sender.setup ok ') tot = 0 for item in pharm_items['response']['body']['items']['item']: tot = tot + 1 item['inputDate'] = today item['inputType'] = '약국' event.Event('getParmacyBasisList_getHospBasisList', item) if tot % 5000 == 0: print(today, '-> TD 전송 약국진행건수 : ', tot) print(today, '-> TD 전송 약국완료건수 : ', tot) tot = 0 for item in hosp_items['response']['body']['items']['item']: tot = tot + 1 item['inputDate'] = today item['inputType'] = '병원' event.Event('getParmacyBasisList_getHospBasisList', item) if tot % 5000 == 0: print(today, '-> TD 전송 병원진행건수 : ', tot) print(today, '-> TD 전송 병원완료건수 : ', tot) sender.close() break except: retries += 1 wait = 2**(retries - 1) time.sleep(wait)
from fluent import sender, event import time, random, timeit sender.setup('poc', host='127.0.0.1', port=24224) while True: event.Event('Export', { 'size': random.randrange(0, 10000000), 'user': '******' }) print(".") time.sleep(0.8) sender.close() # Shell command (ran in pipenv) to measure send function execution time. Avg. 30-50 usec # python -m timeit -s 'from fluent import sender, event; sender.setup("poc", host="127.0.0.1", port=24224)' 'event.Event("test", {"test": 1})'