can run playwright in multi-threads
This commit is contained in:
+22
-22
@@ -8,7 +8,6 @@ from typing import Union
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
import params
|
||||
from workers.commandor_page import get_random_id_number_for_proxy
|
||||
from logs.LogSender import TYPE_EVENT_CHECK_RESULTS, LOG_SUBJECT_EVENT
|
||||
from pojo.ReserveResultPojo import ReserveResultPojo, PublishType
|
||||
|
||||
@@ -25,7 +24,7 @@ class ResultEnum(Enum):
|
||||
|
||||
class TlsPlaywright(threading.local):
|
||||
def __init__(self) -> None:
|
||||
self.playwright = params.SINGLE_PLAYWRIGHT_INSTANCE
|
||||
self.playwright = sync_playwright().start()
|
||||
print("Create playwright instance in Thread", threading.current_thread().name)
|
||||
|
||||
|
||||
@@ -76,7 +75,7 @@ class ResultChecker:
|
||||
}
|
||||
while content is None:
|
||||
content = self.load_page(self.tls.playwright, proxy, url)
|
||||
random_id_number = get_random_id_number_for_proxy()
|
||||
random_id_number = params.get_random_id_number_for_proxy()
|
||||
proxy_username = "panleicim-res-fr-" + random_id_number
|
||||
print("proxy_username is " + proxy_username)
|
||||
proxy = {
|
||||
@@ -110,24 +109,25 @@ if __name__ == '__main__':
|
||||
db_manager = params.firebase_store_manager
|
||||
collection = db_manager.get_all_successful_items_for_day("2022-05-14", "landd")
|
||||
count = 0
|
||||
# result_pojo = ReserveResultPojo(type=PublishType.SUCCESS, phone="0649614591", email="panleicim@gmail.com",
|
||||
# message="SUCCESS", firstName="Lei", lastName="PAN", url='https://api.ipify.org')
|
||||
result_pojo = ReserveResultPojo(type=PublishType.SUCCESS, phone="0649614591", email="panleicim@gmail.com",
|
||||
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(reserve_pojo)
|
||||
# result_list.append(result_pojo)
|
||||
for result in result_list:
|
||||
if result.accepted is None or ResultEnum.ACCEPTED.value == result.accepted:
|
||||
ResultChecker().run(result, collection)
|
||||
else:
|
||||
print("status is " + result.accepted)
|
||||
# for appointment in collection.stream():
|
||||
# reserve_pojo = ReserveResultPojo.from_firestore_dict(appointment.to_dict())
|
||||
# result_list.append(reserve_pojo)
|
||||
result_list.append(result_pojo)
|
||||
# for result in result_list:
|
||||
# if result.accepted is None or ResultEnum.PENDING.value == result.accepted:
|
||||
# ResultChecker().run(result, collection)
|
||||
# else:
|
||||
# print("status is " + result.accepted)
|
||||
|
||||
# with ThreadPoolExecutor(max_workers=1) as executor:
|
||||
# for reserve in result_list:
|
||||
# count = count + 1
|
||||
# if reserve.accepted:
|
||||
# print("status is " + reserve.accepted)
|
||||
# if reserve.accepted is None or ResultEnum.PENDING.value == reserve.accepted:
|
||||
# executor.submit(ResultChecker().run, reserve, collection)
|
||||
# print(count)
|
||||
with ThreadPoolExecutor(max_workers=1) as executor:
|
||||
for reserve in result_list:
|
||||
count = count + 1
|
||||
if reserve.accepted is None or ResultEnum.PENDING.value == reserve.accepted:
|
||||
executor.submit(ResultChecker().run, reserve, collection)
|
||||
else:
|
||||
print("status is " + reserve.accepted)
|
||||
|
||||
print(count)
|
||||
|
||||
Reference in New Issue
Block a user