From e3b4c279fefc734ea51eb3324eed756bdb74c64b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E4=B8=BA=E4=B9=8B?= <560397@gree.com.cn> Date: Tue, 21 Nov 2023 11:27:59 +0800 Subject: [PATCH] Update project --- application/libs/__init__.py | 2 +- application/libs/flask_consul/consul.py | 2 +- application/libs/tasks/task.py | 41 ++++++++++++++++++++----- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/application/libs/__init__.py b/application/libs/__init__.py index 27fc3de..e7ce33e 100644 --- a/application/libs/__init__.py +++ b/application/libs/__init__.py @@ -12,6 +12,6 @@ from .config import ConsulConfig, LocalConfig from .error import ConfigKeyError +from .flask_consul import FlaskConsulService from .flask_elasticsearch import FlaskElasticsearch from .flask_loguru import FlaskLoguru -from .flask_consul import FlaskConsulService diff --git a/application/libs/flask_consul/consul.py b/application/libs/flask_consul/consul.py index f644c7b..e68482d 100644 --- a/application/libs/flask_consul/consul.py +++ b/application/libs/flask_consul/consul.py @@ -13,7 +13,7 @@ import atexit import consul -from flask import current_app, Flask +from flask import Flask from application.libs.helper import ConfigHelper from application.libs.helper import EnvVarHelper diff --git a/application/libs/tasks/task.py b/application/libs/tasks/task.py index 3841aa0..5180d22 100644 --- a/application/libs/tasks/task.py +++ b/application/libs/tasks/task.py @@ -10,27 +10,48 @@ # @Description : """ +# Import built-in modules import datetime +# Import custom modules from application.dao import LogDao from application.extensions.init_sqlalchemy import db def task(): """ - Some Tasks. + Execute some tasks. - :return: None + This function defines a task to parse logs between two specific datetime points. + The task uses the application's database context and configurations for the Elasticsearch index + and an additional database. + + It uses the `parse` method from `LogDao` to process the logs. + + Note: The start and end dates are hardcoded in this example. + + Returns: + None """ - # end_stamp = datetime.datetime.now() - # start_stamp = end_stamp - datetime.timedelta(days=1) - # start = start_stamp.strftime('%Y-%m-%d %H:%M:%S') - # end = end_stamp.strftime('%Y-%m-%d %H:%M:%S') - start = "2021-11-08 00:00:00" - end = "2021-11-09 00:00:00" + # You can uncomment the following lines to use the current date and time and the previous day's date and time + end_stamp = datetime.datetime.now() + start_stamp = end_stamp - datetime.timedelta(days=1) + start = start_stamp.strftime('%Y-%m-%d %H:%M:%S') + end = end_stamp.strftime('%Y-%m-%d %H:%M:%S') + + # Here the start and end dates are hardcoded + # start = "2021-11-08 00:00:00" + # end = "2021-11-09 00:00:00" + + # Use the application's database context with db.app.app_context(): + # Get the Elasticsearch index from the application's configuration index = db.app.config.Elasticsearch.Index + + # Get the ExtraDB configuration from the application's configuration cfg = db.app.config.ExtraDB + + # Create a dictionary of options for the additional database options = { "host": cfg.Host, "user": cfg.User, @@ -38,6 +59,10 @@ def task(): "database": cfg.DB, "port": cfg.Port, } + + # Get the SQL query from the ExtraDB configuration sql = cfg.Sql + + # Call the parse method from LogDao with the necessary parameters LogDao.parse(start, end, index, sql, options) -- GitLab