Merge branch 'feature/stop_at_hour' of bitbucket.org:panleicim/appointment_request into feature/stop_at_hour
This commit is contained in:
+12
-13
@@ -43,10 +43,6 @@ def filter_contacts(_contact_list: list) -> list:
|
||||
return _contact_list_to_book
|
||||
|
||||
|
||||
def is_open():
|
||||
return is_time_between(datetime.time(10, 30), datetime.time(19, 00))
|
||||
|
||||
|
||||
count = 0
|
||||
init_logger()
|
||||
logger = logging.getLogger()
|
||||
@@ -54,7 +50,7 @@ logger = logging.getLogger()
|
||||
logger.addHandler(logging.StreamHandler(stream=sys.stdout))
|
||||
|
||||
|
||||
def send_appointment_request(message_queue_name, _contact_list):
|
||||
def send_appointment_request(message_queue_name, _contact_list, stop_at_hour=11, stop_at_mins=30):
|
||||
global count
|
||||
count = count + 1
|
||||
for _contact in _contact_list:
|
||||
@@ -66,12 +62,14 @@ def send_appointment_request(message_queue_name, _contact_list):
|
||||
receiver = AppointmentRequestSender(sub_contact_list=_contact_list,
|
||||
queue_name=message_queue_name,
|
||||
cookiesPublisher=_cookiesPublisher,
|
||||
bakeUpCookiesPublisher=_backUp_cookiesPublisher, logger=logger)
|
||||
bakeUpCookiesPublisher=_backUp_cookiesPublisher, logger=logger,
|
||||
stop_at_hour=stop_at_hour, stop_at_mins=stop_at_mins)
|
||||
print("count is " + str(count))
|
||||
receiver.run()
|
||||
|
||||
|
||||
def start_send_requests(thread_number, contact_list, data_queue_name=MORNING_DATA_CACHE):
|
||||
def start_send_requests(thread_number, contact_list, data_queue_name=MORNING_DATA_CACHE, stop_at_hour=14,
|
||||
stop_at_mins=56):
|
||||
print("start send requests")
|
||||
_contact_list_to_book = filter_contacts(contact_list)
|
||||
_segment_number = thread_number
|
||||
@@ -82,20 +80,21 @@ def start_send_requests(thread_number, contact_list, data_queue_name=MORNING_DAT
|
||||
logger.info("segment is {}".format(i))
|
||||
_step = int(len(_contact_list_to_book) / _segment_number)
|
||||
_sublist = _contact_list_to_book[i * _step:_step * (i + 1)]
|
||||
_thread1 = Thread(target=send_appointment_request, args=(data_queue_name, _sublist))
|
||||
_thread1 = Thread(target=send_appointment_request, args=(data_queue_name, _sublist, stop_at_hour, stop_at_mins))
|
||||
thread_list.append(_thread1)
|
||||
_thread1.start()
|
||||
for _thread in thread_list:
|
||||
_thread.join()
|
||||
|
||||
|
||||
def send_request_for_file_list(file_list: list[str], thread_number: int = 20, data_queue_name=MORNING_DATA_CACHE):
|
||||
def send_request_for_file_list(file_list: list, thread_number: int = 20, data_queue_name=MORNING_DATA_CACHE,
|
||||
stop_at_hour=11, stop_at_mins=30):
|
||||
for _file_path in file_list:
|
||||
logger.info("send request for file: " + _file_path)
|
||||
_contact_list = read_contacts(_file_path)
|
||||
random.shuffle(_contact_list)
|
||||
start_send_requests(thread_number=thread_number, contact_list=_contact_list,
|
||||
data_queue_name=data_queue_name)
|
||||
data_queue_name=data_queue_name, stop_at_hour=stop_at_hour, stop_at_mins=stop_at_mins)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
@@ -104,6 +103,6 @@ if __name__ == '__main__':
|
||||
# '~/Desktop/contact_list_2024-05-21.xlsx',
|
||||
# '~/Desktop/15_05_to_test.xlsx']
|
||||
# file_list = ['~/Desktop/15_05_to_test.xlsx', '~/Desktop/16_05_to_test.xlsx']
|
||||
file_list = ['~/Desktop/contact_list_2024-07-25.xlsx']
|
||||
send_request_for_file_list(file_list=file_list, thread_number=100,
|
||||
data_queue_name=MORNING_DATA_CACHE)
|
||||
file_list = ['~/Desktop/contact_list_all.xlsx']
|
||||
send_request_for_file_list(file_list=file_list, thread_number=2,
|
||||
data_queue_name=MORNING_DATA_CACHE, stop_at_hour=16, stop_at_mins=30)
|
||||
|
||||
Reference in New Issue
Block a user