diff --git a/application/libs/__init__.py b/application/libs/__init__.py index 27fc3de22ca1a14b31cfbb4b3fe904714f1f87d0..e7ce33ef405801e81e63284cb6d67226c52ecbde 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 f644c7b3e3c938804c12dfb3bd915a108f21ff7e..e68482d48affbb0aed7f177229247aa0a8c80584 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 3841aa0a0dfca9f6529b5c4c9c16aefa0ad9dad7..5180d221b471adb082e95fedafd81de82de0d182 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)