Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/backend.py
Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | class VaultBackend: | ||||
current_version = 4 | current_version = 4 | ||||
def __init__(self, **config): | def __init__(self, **config): | ||||
self.config = config | self.config = config | ||||
self.cache = VaultCache(**config["cache"]) | self.cache = VaultCache(**config["cache"]) | ||||
self.scheduler = get_scheduler(**config["scheduler"]) | self.scheduler = get_scheduler(**config["scheduler"]) | ||||
self.storage = get_storage(**config["storage"]) | self.storage = get_storage(**config["storage"]) | ||||
self.smtp_server = smtplib.SMTP(**config.get("smtp", {})) | |||||
if "db" not in self.config: | if "db" not in self.config: | ||||
raise ValueError( | raise ValueError( | ||||
"The 'db' configuration entry is missing " | "The 'db' configuration entry is missing " | ||||
"in the vault configuration file" | "in the vault configuration file" | ||||
) | ) | ||||
db_conn = config["db"] | db_conn = config["db"] | ||||
self._pool = psycopg2.pool.ThreadedConnectionPool( | self._pool = psycopg2.pool.ThreadedConnectionPool( | ||||
▲ Show 20 Lines • Show All 396 Lines • ▼ Show 20 Lines | ) -> None: | ||||
""" | """ | ||||
DELETE FROM vault_notif_email | DELETE FROM vault_notif_email | ||||
WHERE id = %s""", | WHERE id = %s""", | ||||
(n_id,), | (n_id,), | ||||
) | ) | ||||
def _smtp_send(self, msg: MIMEText): | def _smtp_send(self, msg: MIMEText): | ||||
# Reconnect if needed | # Reconnect if needed | ||||
smtp_server = smtplib.SMTP(**self.config.get("smtp", {})) | |||||
try: | try: | ||||
status = self.smtp_server.noop()[0] | status = smtp_server.noop()[0] | ||||
except smtplib.SMTPException: | except smtplib.SMTPException: | ||||
status = -1 | status = -1 | ||||
if status != 250: | if status != 250: | ||||
self.smtp_server.connect("localhost", 25) | # XXX this is doomed | ||||
smtp_server.connect("localhost", 25) | |||||
# Send the message | # Send the message | ||||
self.smtp_server.send_message(msg) | smtp_server.send_message(msg) | ||||
vlorentz: We can keep the previous behavior of leaving connections open.
Why "this is doomed"? | |||||
douarddaAuthorUnsubmitted Done Inline Actions
why would we want this? What are the pros of keeping it open?
because there is no reason to believe there is someone listening on localhost:25 (especially in elastic envs etc). douardda: > We can keep the previous behavior of leaving connections open.
why would we want this? What… | |||||
vlorentzUnsubmitted Not Done Inline Actions
less latency, but it's not a big deal
I'm fine with removing the fallback, I just didn't understand the comment. vlorentz: > why would we want this? What are the pros of keeping it open?
less latency, but it's not a… | |||||
@db_transaction() | @db_transaction() | ||||
def _cache_expire(self, cond, *args, db=None, cur=None) -> None: | def _cache_expire(self, cond, *args, db=None, cur=None) -> None: | ||||
"""Low-level expiration method, used by cache_expire_* methods""" | """Low-level expiration method, used by cache_expire_* methods""" | ||||
# Embedded SELECT query to be able to use ORDER BY and LIMIT | # Embedded SELECT query to be able to use ORDER BY and LIMIT | ||||
cur.execute( | cur.execute( | ||||
""" | """ | ||||
DELETE FROM vault_bundle | DELETE FROM vault_bundle | ||||
Show All 29 Lines |
We can keep the previous behavior of leaving connections open.
Why "this is doomed"?