teams-alerter 0.2.5__tar.gz → 0.2.6__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: teams-alerter
3
- Version: 0.2.5
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "teams-alerter"
7
- version = "0.2.5"
7
+ version = "0.2.6"
8
8
  description = "Module pour envoyer des alertes Teams via Pub/Sub"
9
9
  authors = [{ name = "Toki", email = "t.bakotondrabe-ext@paris-turf.com" }]
10
10
  readme = "README.md"
@@ -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",
@@ -94,31 +95,35 @@ class TeamsAlerter:
94
95
  self.payload["email_object"] = "Contrôle DATASTREAM"
95
96
 
96
97
  if self.utils["app_name"] == "health_check_check_horses_stats":
97
- error_info_list = json.loads(self.payload["detail"]["message"])
98
- table_data = [("ID CHEVAL", "CHAMP", "POSTGRES", "MONGO", "DIFFERENCE")]
99
- for error_info in error_info_list["data"]:
100
- table_data.append(
101
- (
102
- error_info["idCheval"],
103
- error_info["champ"],
104
- error_info["postgres"],
105
- error_info["mongo"],
106
- 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
+ )
107
111
  )
108
- )
109
-
110
- email_object = "Contrôle DATASTREAM - Fiche cheval"
111
- self.payload["email_object"] = email_object
112
- email_messages = [
113
- """
114
- Bonjour, <br>
115
- Veuillez trouver ci-dessous le tableau récapitulatif du contrôle effectué sur la fiche cheval dans Datastream.
116
- """,
117
- f"""
118
- Env: <strong>{self.utils["env"]}</strong> <br>
119
- Timestamp: {DateUtils.get_str_utc_timestamp()} <br>
120
- Champs: <strong>formFigs et/ou totalPrize</strong>
121
- """,
122
- ]
123
-
124
- self.payload["email_template_html"] = format_email_template(email_object, email_messages, table_data)
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"])
@@ -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.5
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
File without changes
File without changes