added prototype queue for mailing
This commit is contained in:
parent
0bb0cece15
commit
d7b81c9828
16
modules/mailing.py
Normal file
16
modules/mailing.py
Normal file
@ -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"
|
49
modules/queue.py
Normal file
49
modules/queue.py
Normal file
@ -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()
|
Loading…
Reference in New Issue
Block a user