Started threadpoolexecutor branch
This commit is contained in:
24
wallamanta/search_manager.py
Normal file
24
wallamanta/search_manager.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import threading
|
||||
import time
|
||||
import concurrent.futures
|
||||
|
||||
import worker
|
||||
import walladb
|
||||
import helpers
|
||||
import constants
|
||||
|
||||
def work():
|
||||
searches = []
|
||||
|
||||
products = walladb.get_all_valid_products()
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
|
||||
future_to_product = {executor.submit(worker.Worker.first_run, product, 60): product for product in products}
|
||||
for future in concurrent.futures.as_completed(future_to_product):
|
||||
product = future_to_product[future]
|
||||
try:
|
||||
searches[product['id']] = future.result()
|
||||
#first_run_list = future.result()
|
||||
except Exception as e:
|
||||
print(f"Error occurred: {e}")
|
||||
else:
|
||||
print(f"First run for {product['name']} - {product['id']} got: {searches[product['id']]}")
|
||||
@@ -279,6 +279,17 @@ def get_all_products():
|
||||
con.close()
|
||||
return ret
|
||||
|
||||
def get_all_valid_products():
|
||||
with connect_db() as con:
|
||||
#con.row_factory = dict_factory
|
||||
with con.cursor(dictionary=True, prepared=True) as cur:
|
||||
cur.execute(f"SELECT products.* FROM products WHERE products.telegram_user_id IN (SELECT users.telegram_user_id FROM users WHERE active = 1)")
|
||||
try:
|
||||
ret = cur.fetchall()
|
||||
except:
|
||||
ret = None
|
||||
return ret
|
||||
|
||||
def add_product(product):
|
||||
condition = 'all'
|
||||
product_name = product.get('product_name').lower()
|
||||
|
||||
Reference in New Issue
Block a user