diff --git a/modules/mailing.py b/modules/mailing.py new file mode 100644 index 0000000..a4c0bea --- /dev/null +++ b/modules/mailing.py @@ -0,0 +1,16 @@ +from abc import abstractmethod + + +class MailingMethod: + @abstractmethod + def send(self): ... + +class SMTPMAiling(MailingMethod): + + def send(self): + return "SMTP" + +class WhatsAppMailing(MailingMethod): + + def send(self): + return "WhatsApp" \ No newline at end of file diff --git a/modules/queue.py b/modules/queue.py new file mode 100644 index 0000000..2c7ac84 --- /dev/null +++ b/modules/queue.py @@ -0,0 +1,49 @@ +from dataclasses import dataclass, field +import queue +import threading +from time import sleep + +@dataclass +class Item: + type_mailing: str = field(default_factory=str) + company: str = field(default_factory=str) + to: str = field(default_factory=str) + text: str = field(default_factory=str) + status: str = field(default_factory=str) + error_message: str = field(default_factory=str) + +class QueuePool: + def __init__(self) -> None: + self.id = int + self.list_items = [] + self.sended_item = [] + self.error_item = [] + self.queue = queue.Queue() + self.__start() + + def add_to_queue(self, type_mailing: str, company: str, to: str, text: str): + self.list_items.append(Item( + type_mailing=type_mailing, + company=company, + to=to, + text=text, + status="pending" + )) + + def __worker(self): + while True: + # here will be a function for mailing + item = self.queue.get() + print("=====") + print(f"Send to: {item.to}") + sleep(2) # timeout between messages + print("Timeount is end") + self.queue.task_done() + + def __start(self): + threading.Thread(target=self.__worker, daemon=True).start() + + def run_mailing(self): + for item in self.list_items: + self.queue.put(item) + self.queue.join()