add more logs

This commit is contained in:
Lei PAN
2022-06-07 13:44:56 +02:00
parent 1b83084079
commit 09189fb6d0
2 changed files with 15 additions and 0 deletions
+11
View File
@@ -5,6 +5,7 @@ import firebase_admin
from firebase_admin import credentials, firestore from firebase_admin import credentials, firestore
import definitions import definitions
import params
from pojo import ResultEnum from pojo import ResultEnum
from pojo.MailPojo import MailPojo from pojo.MailPojo import MailPojo
from pojo.ReserveResultPojo import ReserveResultPojo from pojo.ReserveResultPojo import ReserveResultPojo
@@ -27,25 +28,30 @@ class DataManager:
self._db = firestore.client() self._db = firestore.client()
def get_all_sim_infos(self): def get_all_sim_infos(self):
params.oracle_log_sender.send_read_db_event("get_all_sim_infos")
sim_info_collection = self._db.collection(SIM_INFOS) sim_info_collection = self._db.collection(SIM_INFOS)
return sim_info_collection return sim_info_collection
def get_all_successful_items(self): def get_all_successful_items(self):
params.oracle_log_sender.send_read_db_event("get_all_successful_items")
return self.get_all_successful_items_for_day(str(datetime.date.today()), None) return self.get_all_successful_items_for_day(str(datetime.date.today()), None)
def get_all_successful_items_for_day(self, day, source_from: Union[str, None]): def get_all_successful_items_for_day(self, day, source_from: Union[str, None]):
params.oracle_log_sender.send_read_db_event("get_all_successful_items_for_day for {}".format(day))
doc_ref = self._db.collection(day) doc_ref = self._db.collection(day)
if source_from is not None: if source_from is not None:
doc_ref.where(u'source_from', u'==', source_from) doc_ref.where(u'source_from', u'==', source_from)
return doc_ref return doc_ref
def get_successful_item_for_day_by_status(self, day, status: ResultEnum): def get_successful_item_for_day_by_status(self, day, status: ResultEnum):
params.oracle_log_sender.send_read_db_event("get_successful_item_for_day_by_status for {}".format(day))
doc_ref = self._db.collection(day) doc_ref = self._db.collection(day)
if status is not None: if status is not None:
doc_ref.where(u'accepted', u'==', status.value) doc_ref.where(u'accepted', u'==', status.value)
return doc_ref return doc_ref
def save_sim_info(self, sim_info: SimInfoPojo): def save_sim_info(self, sim_info: SimInfoPojo):
params.oracle_log_sender.send_read_db_event("save_sim_info")
doc_ref = self._db.collection(SIM_INFOS).document(sim_info.phone) doc_ref = self._db.collection(SIM_INFOS).document(sim_info.phone)
doc_ref.set(sim_info.to_firestore_dict()) doc_ref.set(sim_info.to_firestore_dict())
@@ -57,6 +63,7 @@ class DataManager:
doc_ref.set(result.to_firestore_dict()) doc_ref.set(result.to_firestore_dict())
def find_appointment_detail_via_phone(self, day, phone) -> ReserveResultPojo: def find_appointment_detail_via_phone(self, day, phone) -> ReserveResultPojo:
params.oracle_log_sender.send_read_db_event("find_appointment_detail_via_phone")
doc_ref = self._db.collection(day) doc_ref = self._db.collection(day)
results = doc_ref.where(u'phone', u'==', phone).stream() results = doc_ref.where(u'phone', u'==', phone).stream()
result_list = [] result_list = []
@@ -70,6 +77,7 @@ class DataManager:
doc_ref.set(contact.to_firestore_dict()) doc_ref.set(contact.to_firestore_dict())
def _delete_collection(self, coll_ref, batch_size): def _delete_collection(self, coll_ref, batch_size):
params.oracle_log_sender.send_read_db_event("_delete_collection")
docs = coll_ref.limit(batch_size).stream() docs = coll_ref.limit(batch_size).stream()
deleted = 0 deleted = 0
@@ -83,14 +91,17 @@ class DataManager:
# 删除数据库中所有的sim卡信息 # 删除数据库中所有的sim卡信息
def clear_all_sim_info(self): def clear_all_sim_info(self):
params.oracle_log_sender.send_read_db_event("clear_all_sim_info")
coll_ref = self._db.collection(SIM_INFOS) coll_ref = self._db.collection(SIM_INFOS)
self._delete_collection(coll_ref, self.batch_size) self._delete_collection(coll_ref, self.batch_size)
def read_contacts_from_db(self) -> list: def read_contacts_from_db(self) -> list:
params.oracle_log_sender.send_read_db_event("read_contacts_from_db")
contact_collection = self._db.collection(CONTACT_COLLECTION_NAME) contact_collection = self._db.collection(CONTACT_COLLECTION_NAME)
return contact_collection return contact_collection
def get_mail_list(self) -> list: def get_mail_list(self) -> list:
params.oracle_log_sender.send_read_db_event("get_mail_list")
mail_collection = self._db.collection(MAIL_COLLECTION_NAME) mail_collection = self._db.collection(MAIL_COLLECTION_NAME)
mail_list = [] mail_list = []
for mail in mail_collection.stream(): for mail in mail_collection.stream():
+4
View File
@@ -18,6 +18,7 @@ LOG_SUBJECT_SMS = "SMS"
SUBJECT_SIM_INFO = "sim_card" SUBJECT_SIM_INFO = "sim_card"
# Log type # Log type
TYPE_EVENT_CHECK_RESULTS = "EVENT_CHECK_RESULTS" TYPE_EVENT_CHECK_RESULTS = "EVENT_CHECK_RESULTS"
TYPE_EVENT_READ_DB = "EVENT_READ_DB"
TYPE_EVENT_RESET_ALL_SIM_CARDS = "EVENT_RESET_ALL_SIM_CARDS" TYPE_EVENT_RESET_ALL_SIM_CARDS = "EVENT_RESET_ALL_SIM_CARDS"
TYPE_EVENT_CHANGE_SLOT = "EVENT_CHANGE_SLOT" TYPE_EVENT_CHANGE_SLOT = "EVENT_CHANGE_SLOT"
TYPE_SMS_RECEIVED = "TYPE_SMS_RECEIVED" TYPE_SMS_RECEIVED = "TYPE_SMS_RECEIVED"
@@ -94,6 +95,9 @@ class LogSender:
def send_error(self, msg: str): def send_error(self, msg: str):
self.send_log(msg=msg, type=LOG_ERROR) self.send_log(msg=msg, type=LOG_ERROR)
def send_read_db_event(self, msg: str):
self.send_log(msg=msg, type=TYPE_EVENT_READ_DB, subject=LOG_SUBJECT_EVENT)
def send_log(self, msg: str, source=definitions.LOG_SOURCE, subject="appointment", type: str = "INFO"): def send_log(self, msg: str, source=definitions.LOG_SOURCE, subject="appointment", type: str = "INFO"):
log_id = "ocid1.log.oc1.eu-frankfurt-1.amaaaaaas4ft22ya3ub6glkltqqbnmkxo3ui7xwq3dxtjd2scdhme4deyu2q" log_id = "ocid1.log.oc1.eu-frankfurt-1.amaaaaaas4ft22ya3ub6glkltqqbnmkxo3ui7xwq3dxtjd2scdhme4deyu2q"
response = self._loggingingestion_client.put_logs( response = self._loggingingestion_client.put_logs(