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
d1a29e12
Commit
d1a29e12
authored
Nov 07, 2023
by
崔为之
💪🏽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update project
parent
91d7e7bb
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
83 additions
and
37 deletions
+83
-37
application/config/config.yaml
application/config/config.yaml
+7
-0
application/extensions/__init__.py
application/extensions/__init__.py
+2
-0
application/extensions/init_celery.py
application/extensions/init_celery.py
+3
-36
application/libs/__init__.py
application/libs/__init__.py
+1
-0
application/libs/tasks/__init__.py
application/libs/tasks/__init__.py
+13
-0
application/libs/tasks/task.py
application/libs/tasks/task.py
+56
-0
application/utils/__init__.py
application/utils/__init__.py
+1
-1
No files found.
application/config/config.yaml
View file @
d1a29e12
...
...
@@ -30,3 +30,10 @@ Logger:
Rotation
:
Enqueue
:
True
Retention
:
Redis
:
Host
:
localhost
Port
:
6379
Username
:
Password
:
DB
:
13
application/extensions/__init__.py
View file @
d1a29e12
...
...
@@ -21,6 +21,7 @@ from .init_migrate import init_migrate
from
.init_apispec
import
init_apispec
from
.init_marshmallow
import
init_marshmallow
from
.init_elasticsearch
import
init_elasticsearch
from
.init_celery
import
init_celery
def
init_plugs
(
app
:
Flask
)
->
None
:
...
...
@@ -33,3 +34,4 @@ def init_plugs(app: Flask) -> None:
init_marshmallow
(
app
)
init_elasticsearch
(
app
)
init_cors
(
app
)
init_celery
(
app
)
application/extensions/init_celery.py
View file @
d1a29e12
...
...
@@ -10,43 +10,10 @@
# @Description :
"""
from
flask
import
Flask
from
celery
import
Celery
from
celery.schedules
import
crontab
def
init_celery
(
app
:
Flask
)
->
None
:
"""
Initialize Celery for the Flask application.
:param app: The Flask application.
:type app: Flask
"""
celery
=
Celery
(
app
.
import_name
,
backend
=
app
.
config
[
'CELERY_RESULT_BACKEND'
],
broker
=
app
.
config
[
'CELERY_BROKER_URL'
]
)
celery
.
conf
.
update
(
app
.
config
)
from
application.libs
import
make_celery
class
ContextTask
(
celery
.
Task
):
def
__call__
(
self
,
*
args
,
**
kwargs
):
with
app
.
app_context
():
return
self
.
run
(
*
args
,
**
kwargs
)
celery
.
Task
=
ContextTask
@
celery
.
task
()
def
update_database
():
# Add your database operations here
pass
celery
.
conf
.
beat_schedule
=
{
'update-database-every-day'
:
{
'task'
:
'update_database'
,
'schedule'
:
crontab
(
hour
=
0
,
minute
=
0
)
# Execute daily at midnight
}
}
app
.
celery
=
celery
def
init_celery
(
app
:
Flask
)
->
None
:
app
.
celery
=
make_celery
(
app
)
application/libs/__init__.py
View file @
d1a29e12
...
...
@@ -14,3 +14,4 @@ from .config import ConsulConfig, LocalConfig
from
.error
import
ConfigKeyError
from
.flask_elasticsearch
import
FlaskElasticsearch
from
.flask_loguru
import
FlaskLoguru
from
.tasks
import
make_celery
application/libs/tasks/__init__.py
0 → 100644
View file @
d1a29e12
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
# @Version : Python 3.11.4
# @Software : Sublime Text 4
# @Author : StudentCWZ
# @Email : StudentCWZ@outlook.com
# @Date : 2023/11/7 16:16
# @File : __init__.py.py
# @Description :
"""
from
.task
import
make_celery
application/libs/tasks/task.py
0 → 100644
View file @
d1a29e12
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
# @Version : Python 3.11.4
# @Software : Sublime Text 4
# @Author : StudentCWZ
# @Email : StudentCWZ@outlook.com
# @Date : 2023/11/7 16:16
# @File : task.py
# @Description :
"""
from
celery
import
Celery
from
celery.schedules
import
crontab
from
flask
import
Flask
from
application.utils
import
RedisUri
def
make_celery
(
app
:
Flask
)
->
Celery
:
cfg
=
app
.
config
.
Redis
uri
=
RedisUri
(
username
=
cfg
.
Username
,
password
=
cfg
.
Password
,
host
=
cfg
.
Host
,
port
=
int
(
cfg
.
Port
),
db
=
int
(
cfg
.
DB
),
)
print
(
uri
)
celery
=
Celery
(
app
.
import_name
,
backend
=
'redis://localhost:6379/0'
,
broker
=
'redis://localhost:6379/0'
)
celery
.
conf
.
update
(
app
.
config
)
class
ContextTask
(
celery
.
Task
):
def
__call__
(
self
,
*
args
,
**
kwargs
):
with
app
.
app_context
():
return
self
.
run
(
*
args
,
**
kwargs
)
@
celery
.
task
(
base
=
ContextTask
)
def
update_database
():
# Add your database operations here
print
(
1232141241421
)
celery
.
conf
.
beat_schedule
=
{
'update-database-every-day'
:
{
'task'
:
'update_database'
,
'schedule'
:
crontab
(
minute
=
'*'
)
# Execute every minute
}
}
return
celery
application/utils/__init__.py
View file @
d1a29e12
...
...
@@ -10,5 +10,5 @@
# @Description :
"""
from
.dsn
import
DatabaseUri
from
.dsn
import
DatabaseUri
,
RedisUri
from
.elasticsearch
import
ElasticsearchUtil
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