teams-alerter 0.2.4__py3-none-any.whl → 0.2.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
teams_alerter/core.py CHANGED
@@ -2,7 +2,7 @@ import json
2
2
  import traceback
3
3
 
4
4
  from google.cloud import pubsub_v1
5
- from .utils import ErrorUtils, DateUtils, format_email_template
5
+ from .utils import ErrorUtils, DateUtils, format_email_template, is_json
6
6
 
7
7
 
8
8
  class TeamsAlerter:
@@ -56,6 +56,7 @@ class TeamsAlerter:
56
56
  "health_check_check_races_ids",
57
57
  "health_check_check_partants_data",
58
58
  "health_check_check_runners_ids",
59
+ "health_check_check_processing_queue_ids",
59
60
  ],
60
61
  "email": [
61
62
  "health_check_check_horses_stats",
@@ -91,33 +92,38 @@ class TeamsAlerter:
91
92
 
92
93
  def format_email_template(self):
93
94
  self.payload["alert_type"].append("email")
95
+ self.payload["email_object"] = "Contrôle DATASTREAM"
94
96
 
95
97
  if self.utils["app_name"] == "health_check_check_horses_stats":
96
- error_info_list = json.loads(self.payload["detail"]["message"])
97
- table_data = [("ID CHEVAL", "CHAMP", "POSTGRES", "MONGO", "DIFFERENCE")]
98
- for error_info in error_info_list["data"]:
99
- table_data.append(
100
- (
101
- error_info["idCheval"],
102
- error_info["champ"],
103
- error_info["postgres"],
104
- error_info["mongo"],
105
- error_info["difference"],
98
+ if is_json(self.payload["detail"]["message"]):
99
+ # cette ligne plante si message n'est pas json
100
+ error_info_list = json.loads(self.payload["detail"]["message"])
101
+ table_data = [("ID CHEVAL", "CHAMP", "POSTGRES", "MONGO", "DIFFERENCE")]
102
+ for error_info in error_info_list["data"]:
103
+ table_data.append(
104
+ (
105
+ error_info["idCheval"],
106
+ error_info["champ"],
107
+ error_info["postgres"],
108
+ error_info["mongo"],
109
+ error_info["difference"],
110
+ )
106
111
  )
107
- )
108
-
109
- email_object = "Contrôle DATASTREAM - Fiche cheval"
110
- email_messages = [
111
- """
112
- Bonjour, <br>
113
- Veuillez trouver ci-dessous le tableau récapitulatif du contrôle effectué sur la fiche cheval dans Datastream.
114
- """,
115
- f"""
116
- Env: <strong>{self.utils["env"]}</strong> <br>
117
- Timestamp: {DateUtils.get_str_utc_timestamp()} <br>
118
- Champs: <strong>formFigs et/ou totalPrize</strong>
119
- """,
120
- ]
121
-
122
- self.payload["email_template_html"] = format_email_template(email_object, email_messages, table_data)
123
- print(self.payload["email_template_html"])
112
+
113
+ email_object = "Contrôle DATASTREAM - Fiche cheval"
114
+ self.payload["email_object"] = email_object
115
+ email_messages = [
116
+ """
117
+ Bonjour, <br>
118
+ Veuillez trouver ci-dessous le tableau récapitulatif du contrôle effectué sur la fiche cheval dans Datastream.
119
+ """,
120
+ f"""
121
+ Env: <strong>{self.utils["env"]}</strong> <br>
122
+ Timestamp: {DateUtils.get_str_utc_timestamp()} <br>
123
+ Champs: <strong>formFigs et/ou totalPrize</strong>
124
+ """,
125
+ ]
126
+
127
+ self.payload["email_template_html"] = format_email_template(email_object, email_messages, table_data)
128
+ else:
129
+ print("⚠ ERREUR INTERNE : error_message n'est pas un JSON valide :", self.payload["detail"]["message"])
teams_alerter/utils.py CHANGED
@@ -1,4 +1,5 @@
1
1
  import datetime
2
+ import json
2
3
 
3
4
  from typing import TypedDict
4
5
  from google.cloud import logging
@@ -122,3 +123,13 @@ def build_html_message(email_messages: list[str]):
122
123
  </tr>
123
124
  """
124
125
  return content
126
+
127
+
128
+ def is_json(value):
129
+ if not isinstance(value, str):
130
+ return False # ce n'est même pas une chaîne
131
+ try:
132
+ json.loads(value)
133
+ return True
134
+ except json.JSONDecodeError:
135
+ return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: teams-alerter
3
- Version: 0.2.4
3
+ Version: 0.2.6
4
4
  Summary: Module pour envoyer des alertes Teams via Pub/Sub
5
5
  Author-email: Toki <t.bakotondrabe-ext@paris-turf.com>
6
6
  License: MIT
@@ -0,0 +1,9 @@
1
+ teams_alerter/__init__.py,sha256=J6zyyTfUNVElXD0wsTqBwp-VtcApbzYGUPpChrdcbpY,131
2
+ teams_alerter/core.py,sha256=XSsFRdTcHIbH2ec7KavNPnl2DuNQA2UIMO5qV4wIGMM,5467
3
+ teams_alerter/utils.py,sha256=lA_BATVjYEEreTiiCIUbT_KqOxi0XUiMCUE5qkXpEhg,5586
4
+ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ tests/test_core.py,sha256=Bd3rxUUXAYM3oKK4Gs5u2AF4-Di5oSmXsMeHINfEHyM,3089
6
+ teams_alerter-0.2.6.dist-info/METADATA,sha256=bVygo8dVEMp0SJ8NPmwRYjcHxEs1I2TAOxjqg7kLsrM,2194
7
+ teams_alerter-0.2.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ teams_alerter-0.2.6.dist-info/top_level.txt,sha256=eLk39V0LcwZmxaC5MkgLKvTLeBaox3XkfSvXxm7GVik,20
9
+ teams_alerter-0.2.6.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- teams_alerter/__init__.py,sha256=J6zyyTfUNVElXD0wsTqBwp-VtcApbzYGUPpChrdcbpY,131
2
- teams_alerter/core.py,sha256=oWKn8tNNDJ6Vd-2wFyAZHjoo_stU1PcyY_M5KRaKyjc,4964
3
- teams_alerter/utils.py,sha256=jP3JTnrOmriz60aWbmzc76P_xrETxvJNsUS1TCcz94Y,5342
4
- tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- tests/test_core.py,sha256=Bd3rxUUXAYM3oKK4Gs5u2AF4-Di5oSmXsMeHINfEHyM,3089
6
- teams_alerter-0.2.4.dist-info/METADATA,sha256=vdBtGz_LIMdnGoEv4UPR0CQG_nOSSgcAZv2y855yQgU,2194
7
- teams_alerter-0.2.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
- teams_alerter-0.2.4.dist-info/top_level.txt,sha256=eLk39V0LcwZmxaC5MkgLKvTLeBaox3XkfSvXxm7GVik,20
9
- teams_alerter-0.2.4.dist-info/RECORD,,