need to test singleton

This commit is contained in:
2022-07-25 14:21:12 +02:00
parent 3160fefdab
commit f482164c16
4 changed files with 48 additions and 17 deletions
+5 -5
View File
@@ -2,7 +2,7 @@ import logging
import sys
from concurrent.futures import ThreadPoolExecutor
from src import params, definitions
from src import params
from src.db.mongo_manager import MONGO_STORE_MANAGER
from src.logs.AppLogging import init_logger
from src.pojo.ModeEnum import ModeEnum
@@ -40,7 +40,7 @@ def start_book(start_number, end_number, store_choose_state=0, max_workers=20, p
def recheck_the_captcha_error_contacts(on_no_contact_found, store_type=0, mode: ModeEnum = ModeEnum.MANUAL,
max_workers=20):
max_workers=20, headless=False):
# get all the contacts in captcha error
contact_list = MONGO_STORE_MANAGER.get_captcha_error_contacts_for_current_day()
if len(contact_list) == 0:
@@ -51,7 +51,7 @@ def recheck_the_captcha_error_contacts(on_no_contact_found, store_type=0, mode:
proxy = get_proxy()
# start the task in thread
executor.submit(
CommandorPage(contact, store_type=store_type, mode=mode).start_page,
CommandorPage(contact, store_type=store_type, mode=mode, headless= headless).start_page,
proxy)
@@ -61,5 +61,5 @@ def get_proxy(proxy_type=ProxyType.BRIGHT_DATA):
if __name__ == '__main__':
# 修改联系人行,结束联系人行 第三个参数store等于0的时候是随机,传入1的时候是总店
start_book(901, 1200, store_choose_state=1, mode=ModeEnum.AUTOMATIC, headless=True)
# recheck_the_captcha_error_contacts(store_type=1, mode=ModeEnum.AUTOMATIC, on_no_contact_found=lambda: None)
# start_book(1, 100, store_choose_state=1, mode=ModeEnum.AUTOMATIC, headless=True)
recheck_the_captcha_error_contacts(store_type=1, mode=ModeEnum.AUTOMATIC, on_no_contact_found=lambda: None, headless=True)
+1 -6
View File
@@ -17,6 +17,7 @@ from src.pojo.ReserveResultPojo import ReserveResultPojo
from src.pojo.ResultEnum import ResultEnum
from src.proxy.proxy_type import ProxyType
from src import definitions, params
from src.workers.TlsPlaywright import TlsPlaywright
SORRY_SENTENCE_FR = "nous sommes sincèrement désolés de n'avoir pu vous satisfaire cette fois-ci"
SORRY_SENTENCE_EN = "we are extremely sorry that we were not able to fulfill"
@@ -31,12 +32,6 @@ mailer = Mailer()
oracle_log_sender = LogSender()
class TlsPlaywright(threading.local):
def __init__(self) -> None:
self.playwright = sync_playwright().start()
print("创建浏览器实例,线程: ", threading.current_thread().name)
class ResultChecker:
tls = TlsPlaywright()
+40
View File
@@ -0,0 +1,40 @@
import threading
from playwright.sync_api import sync_playwright
class OnlyOne:
class __OnlyOne:
def __init__(self, arg):
self.val = arg
def __str__(self):
return repr(self) + self.val
instance = None
def __init__(self, arg):
if not OnlyOne.instance:
OnlyOne.instance = OnlyOne.__OnlyOne(arg)
else:
OnlyOne.instance.val = arg
def __getattr__(self, name):
return getattr(self.instance, name)
class TlsPlaywright():
# private nested inner class
class __TlsPlaywrightSingleton(threading.local):
def __init__(self) -> None:
self.playwright = sync_playwright().start()
print("创建浏览器实例,线程: ", threading.current_thread().name)
playwright = None
def __init__(self):
if not TlsPlaywright.playwright:
TlsPlaywright.playwright = TlsPlaywright.__TlsPlaywrightSingleton().playwright
def __getattr__(self, name):
return getattr(self.playwright, name)
+2 -6
View File
@@ -17,6 +17,7 @@ from src.pojo.ReserveResultPojo import ReserveResultPojo, PublishType
from src.pojo.contact_pojo import ContactPojo
from src.proxy.proxy_type import ProxyType
from src.workers.SolveCaptch import SolveCaptcha
from src.workers.TlsPlaywright import TlsPlaywright
RDV_URL = "https://rendezvousparis.hermes.com/client/register"
@@ -46,13 +47,8 @@ def get_random_wait_time() -> float:
return wait_time
class Tls(threading.local):
def __init__(self) -> None:
self.playwright = sync_playwright().start()
class CommandorPage:
tls = Tls()
tls = TlsPlaywright()
def __init__(self, contact: ContactPojo, store_type=0, proxy_type=ProxyType.BRIGHT_DATA,
mode: ModeEnum = ModeEnum.MANUAL, headless=False):