From e44bc7f64a5b6abc78b5b61896271b67ec024278 Mon Sep 17 00:00:00 2001 From: Migatu Date: Mon, 22 Apr 2024 20:11:50 +0200 Subject: [PATCH] Fixes --- bot.py | 23 +++++------------------ communication_subroutine.py | 23 +++++++++++++++++++++++ conjurer_librarian/search_bot.py | 19 ++++++++++--------- conjurer_musician/radio_conjurer.liq | 4 ++-- 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/bot.py b/bot.py index 0982352..d0c6586 100644 --- a/bot.py +++ b/bot.py @@ -44,7 +44,7 @@ import yt_dlp from spotify_dl import spotify from spotify_dl import youtube as youtube_download -from communication_subroutine import comm_subroutine, IN_COMM_Q, OUT_COMM_Q +from communication_subroutine import comm_subroutine, IN_COMM_Q, OUT_COMM_Q, QueryControl # *=========================== Classes definition @@ -62,22 +62,6 @@ Music_Config = TypedDict( ) -class QueryControl: - """ - This class `QueryControl` is used to manage queries with information about the author, UUID, - content, logger, context, and replies. - """ - def __init__(self, query_author, query_uuid, query_content, uplogger, ctx) -> None: - self.author = query_author - self.uuid = query_uuid - self.content = query_content - self.logger = uplogger - self.stop = False - self.ctx = ctx - self.logger.info( - f"Created Query control for {self.author}, {self.uuid}: {self.content}" - ) - self.replies = [] class MusicFileList(object): """ @@ -695,7 +679,10 @@ async def check_data_q(): entries = [] if fresh_data.stop: searcher = fresh_data.author - ctx = fresh_data.ctx + if fresh_data.ctx is not None: + ctx = fresh_data.ctx + else: + ctx = client.get_channel(1062047367337095268) query = fresh_data.content l_p = 1 for doi in fresh_data.entries: diff --git a/communication_subroutine.py b/communication_subroutine.py index 4b53099..3cda26c 100644 --- a/communication_subroutine.py +++ b/communication_subroutine.py @@ -13,6 +13,22 @@ IN_COMM_Q = Queue() awaiting_q = [] incoming_q = Queue() app = Flask(__name__) +class QueryControl: + """ + This class `QueryControl` is used to manage queries with information about the author, UUID, + content, logger, context, and replies. + """ + def __init__(self, query_author, query_uuid, query_content, uplogger, ctx) -> None: + self.author = query_author + self.uuid = query_uuid + self.content = query_content + self.logger = uplogger + self.stop = False + self.ctx = ctx + self.logger.info( + f"Created Query control for {self.author}, {self.uuid}: {self.content}" + ) + self.replies = [] @app.route("/conjurer", methods=["POST"]) def answer_external_command(): @@ -91,6 +107,13 @@ def scan_incoming(_logger): record.stop = True record.entries = answer[record.uuid] IN_COMM_Q.put(record) + else: + for key in answer.keys(): + record = QueryControl("Orphaned", key, "Orphan", _logger, None) + record.stop = True + record.entries = answer[record.uuid] + record.uuid = "000000" + IN_COMM_Q.put(record) except Empty: time.sleep(1) diff --git a/conjurer_librarian/search_bot.py b/conjurer_librarian/search_bot.py index 52898a2..9c1cb8c 100644 --- a/conjurer_librarian/search_bot.py +++ b/conjurer_librarian/search_bot.py @@ -68,7 +68,7 @@ def producer(out_q, control_q, filename, _logger): # IMPORTANT!!! ONLY ONE CONSUMER THREAD AS WE ARE NOT PUTTING SENTINELS BACK -def consumer(in_q, control_q, doi, live_results, result_list, _logger, ): +def consumer(in_q, control_q, doi, live_results, result_list, control_dict, _logger): """ Consumes items from an input queue and checks if DOI exists in the live results list. @@ -79,7 +79,6 @@ def consumer(in_q, control_q, doi, live_results, result_list, _logger, ): live_results (list): List to store the search results. _logger: Logger object for logging. """ - sentinels = 0 for item in doi: result_list.append({"DOI": item[0], "exists": False, "data": item[1]}) while True: @@ -87,7 +86,7 @@ def consumer(in_q, control_q, doi, live_results, result_list, _logger, ): data = in_q.get() if data is _sentinel: _logger.info("Worker finished") - sentinels += 1 + control_dict["sentinels"] += 1 else: for item in result_list: if item["DOI"] in data and not item["exists"]: @@ -98,7 +97,7 @@ def consumer(in_q, control_q, doi, live_results, result_list, _logger, ): done_check = done_check and item["exists"] if done_check: control_q.put(_sentinel) - if sentinels >= MAXTHREADS: + if control_dict["sentinels"] >= MAXTHREADS: _logger.info("All workers finished") break @@ -112,15 +111,17 @@ def search_for_doi(doi, live_results, _logger): live_results (list): List to store the search results. _logger: Logger object for logging. """ + control_dict = {"sentinels":0} result_list = [] threads = [] work_q = Queue(maxsize=WORK_Q_SIZE) control_q = Queue() - t_cons = Thread( - target=consumer, args=(work_q, control_q, doi, live_results, result_list, _logger) - ) - _logger.info("Consumer thread created") - threads.append(t_cons) + for _ in range (1, len(doi)//1000+1): + t_cons = Thread( + target=consumer, args=(work_q, control_q, doi, live_results, result_list, control_dict, _logger) + ) + _logger.info("Consumer thread created") + threads.append(t_cons) for i in range(0, MAXTHREADS): # TEST DATA # filename = "test" + str(i) + CHUNk diff --git a/conjurer_musician/radio_conjurer.liq b/conjurer_musician/radio_conjurer.liq index 00a75e8..e5a263f 100644 --- a/conjurer_musician/radio_conjurer.liq +++ b/conjurer_musician/radio_conjurer.liq @@ -24,8 +24,8 @@ let json.parse credentials = file.contents("/home/pi/Conjurer/icecast_credentia s3 = replaygain(playlist(reload_mode="watch", check_next=check, "/home/pi/Conjurer/hit.playlist")) requests_queue = request.queue() def queue_processing() - requests_queue.push.uri("/home/pi/Conjurer/request.playlist"), - file.remove("/home/pi/Conjurer/requests_queue.playlist"), + requests_queue.push.uri("/home/pi/Conjurer/request.playlist") + file.remove("/home/pi/Conjurer/requests_queue.playlist") file.touch("/home/pi/Conjurer/requests_queue.playlist") end thread.run(every=60., {queue_processing()})