porbleme of sync resolved

This commit is contained in:
PAN Lei
2022-05-15 23:13:51 +02:00
parent 9e4972c8c9
commit dbdb88600a
4 changed files with 20 additions and 15 deletions
+11 -11
View File
@@ -22,14 +22,14 @@ class ResultEnum(Enum):
PENDING = "PENDING"
class Tls(threading.local):
class TlsPlaywright(threading.local):
def __init__(self) -> None:
self.playwright = sync_playwright().start()
self.playwright = params.SINGLE_PLAYWRIGHT_INSTANCE
print("Create playwright instance in Thread", threading.current_thread().name)
class Worker:
tls = Tls()
class ResultChecker:
tls = TlsPlaywright()
def __init__(self):
self.logger = logging.getLogger("Worker")
@@ -38,7 +38,7 @@ class Worker:
try:
self.browser = playwright.webkit.launch(headless=False, timeout=90000, proxy=proxy)
device = random.choice(params.DEVICES)
self.logger.info("device is " + device)
self.logger.info("模拟设备: " + device)
pixel_2 = self.tls.playwright.devices[device]
context = self.browser.new_context(**pixel_2, locale='en-GB')
self.page = context.new_page()
@@ -104,14 +104,14 @@ if __name__ == '__main__':
# get the list
params.oracle_log_sender.send_log(msg="开始检查约会结果", subject=LOG_SUBJECT_EVENT, type=TYPE_EVENT_CHECK_RESULTS)
db_manager = params.firebase_store_manager
collection = db_manager.get_all_successful_items()
collection = db_manager.get_all_successful_items_for_day()
count = 0
result_pojo = ReserveResultPojo(type=PublishType.SUCCESS, phone="0649614591", email="panleicim@gmail.com",
message="SUCCESS", firstName="Lei", lastName="PAN")
message="SUCCESS", firstName="Lei", lastName="PAN", url='https://api.ipify.org')
result_list = []
for appointment in collection.stream():
reserve_pojo = ReserveResultPojo.from_firestore_dict(appointment.to_dict())
result_list.append(result_pojo)
# for appointment in collection.stream():
# reserve_pojo = ReserveResultPojo.from_firestore_dict(appointment.to_dict())
result_list.append(result_pojo)
with ThreadPoolExecutor(max_workers=2) as executor:
for reserve in result_list:
@@ -119,5 +119,5 @@ if __name__ == '__main__':
if reserve.accepted:
print("status is " + reserve.accepted)
if reserve.accepted is None or ResultEnum.PENDING.value == reserve.accepted:
executor.submit(Worker().run, reserve, collection)
executor.submit(ResultChecker().run, reserve, collection)
print(count)