Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
elp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
崔为之
elp
Commits
e3b4c279
Commit
e3b4c279
authored
Nov 21, 2023
by
崔为之
💪🏽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update project
parent
f7ead397
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
10 deletions
+35
-10
application/libs/__init__.py
application/libs/__init__.py
+1
-1
application/libs/flask_consul/consul.py
application/libs/flask_consul/consul.py
+1
-1
application/libs/tasks/task.py
application/libs/tasks/task.py
+33
-8
No files found.
application/libs/__init__.py
View file @
e3b4c279
...
...
@@ -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
application/libs/flask_consul/consul.py
View file @
e3b4c279
...
...
@@ -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
...
...
application/libs/tasks/task.py
View file @
e3b4c279
...
...
@@ -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 T
asks.
Execute some t
asks.
: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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment