diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/quantifi_status.py | 8 | ||||
| -rw-r--r-- | python/report_ops/status.py | 15 | ||||
| -rw-r--r-- | python/report_ops/utils.py | 40 |
3 files changed, 54 insertions, 9 deletions
diff --git a/python/quantifi_status.py b/python/quantifi_status.py index 04376b2c..0e9edfab 100644 --- a/python/quantifi_status.py +++ b/python/quantifi_status.py @@ -4,7 +4,6 @@ from contextlib import contextmanager from report_ops.status import QuantifiRemote from paramiko.ssh_exception import SSHException import logging -from psycopg.errors import UniqueViolation from contextlib import contextmanager @@ -33,13 +32,6 @@ def run(): try: for f in QuantifiRemote._client.list_files("/OUTGOING/Status"): item = QuantifiRemote.process(f) - item.stage() - try: - item.commit() - except UniqueViolation: - item._conn.rollback() - finally: - item._insert_queue.clear() except (SSHException, OSError): close_and_reconnect() time.sleep(60) diff --git a/python/report_ops/status.py b/python/report_ops/status.py index befaeff3..297a1633 100644 --- a/python/report_ops/status.py +++ b/python/report_ops/status.py @@ -5,10 +5,13 @@ import re import xml.etree.ElementTree as ET from io import BytesIO from functools import lru_cache +from psycopg.errors import UniqueViolation from serenitas.ops.trade_dataclasses import Deal from serenitas.utils.remote import Client +from .utils import QuantifiMonitor + class Remote: _client: ClassVar @@ -63,7 +66,17 @@ class QuantifiRemote( "filename": fname.removesuffix(".xml"), "total": data["items"], } - return cls.from_dict(**data) + item = cls.from_dict(**data) + item.stage() + try: + item.commit() + except UniqueViolation: + item._conn.rollback() + else: + QuantifiMonitor.stage(data) + QuantifiMonitor.email(fname.removesuffix(".xml"), data["errors"] > 0) + finally: + item._insert_queue.clear() @staticmethod def extract_ts(filename): diff --git a/python/report_ops/utils.py b/python/report_ops/utils.py index 54f25526..5b0c14a7 100644 --- a/python/report_ops/utils.py +++ b/python/report_ops/utils.py @@ -502,6 +502,46 @@ class FxHedge( ) +class QuantifiMonitor( + Monitor, + headers=( + "uploadtime", + "filename", + "errors", + "warnings", + "successes", + "total", + ), + num_format=[], +): + @classmethod + def email(cls, filename, errors): + if not cls._staging_queue: + return + cls._em.send_email( + f"Quantifi Report: {filename} {'**Errors**' if errors else ''}", + HTMLBody( + f""" +<html> + <head> + <style> + table, th, td {{ border: 1px solid black; border-collapse: collapse;}} + th, td {{ padding: 5px; }} + </style> + </head> + <body> + {cls.to_tabulate()} + </body> +</html>""" + ), + to_recipients=( + "fyu@lmcg.com", + "ghorel@lmcg.com", + "etsui@lmcg.com", + ), + ) + + @dataclass class EmailOps: _em = ExchangeMessage() |
