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
d3969b3c
Commit
d3969b3c
authored
Nov 11, 2023
by
崔为之
💪🏽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update project
parent
d733b070
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
110 additions
and
1 deletion
+110
-1
application/config/config.yaml
application/config/config.yaml
+5
-0
application/extensions/__init__.py
application/extensions/__init__.py
+2
-0
application/extensions/init_apscheduler.py
application/extensions/init_apscheduler.py
+47
-0
application/libs/flask_apscheduler/__init__.py
application/libs/flask_apscheduler/__init__.py
+13
-0
application/libs/flask_apscheduler/apscheduler.py
application/libs/flask_apscheduler/apscheduler.py
+31
-0
application/libs/tasks/__init__.py
application/libs/tasks/__init__.py
+3
-1
application/libs/tasks/task.py
application/libs/tasks/task.py
+9
-0
No files found.
application/config/config.yaml
View file @
d3969b3c
...
...
@@ -37,3 +37,8 @@ Redis:
Username
:
Password
:
DB
:
13
Scheduler
:
Start
:
2023-11-11 15:20:00
End
:
2099-11-11 16:00:00
Timezone
:
Asia/Shanghai
application/extensions/__init__.py
View file @
d3969b3c
...
...
@@ -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_apscheduler
import
init_tasks
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_tasks
(
app
)
application/extensions/init_apscheduler.py
0 → 100644
View file @
d3969b3c
#!/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/11 14:50
# @File : init_apscheduler.py
# @Description :
"""
from
apscheduler.triggers.interval
import
IntervalTrigger
from
flask
import
Flask
from
application.libs.tasks
import
task
from
application.libs.flask_apscheduler
import
APScheduler
scheduler
=
APScheduler
()
def
init_tasks
(
app
:
Flask
)
->
None
:
"""
Initialize the task extension.
:param app: The Flask application instance.
:return: None
"""
if
not
isinstance
(
app
,
Flask
):
raise
TypeError
(
f
'Expected a Flask application instance, got
{
type
(
app
).
__name__
}
'
)
scheduler
.
api_enabled
=
True
scheduler
.
init_app
(
app
)
# Create an interval trigger
interval
=
IntervalTrigger
(
days
=
1
,
start_date
=
app
.
config
.
Scheduler
.
Start
,
end_date
=
app
.
config
.
Scheduler
.
End
,
timezone
=
app
.
config
.
Scheduler
.
Timezone
)
# Add a job to the scheduler
scheduler
.
add_job
(
func
=
task
,
trigger
=
interval
,
id
=
'task_one'
)
# Start the scheduler
scheduler
.
start
()
application/libs/flask_apscheduler/__init__.py
0 → 100644
View file @
d3969b3c
#!/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/11 15:15
# @File : __init__.py.py
# @Description :
"""
from
.apscheduler
import
APScheduler
application/libs/flask_apscheduler/apscheduler.py
0 → 100644
View file @
d3969b3c
#!/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/11 15:15
# @File : apscheduler.py
# @Description :
"""
from
flask_apscheduler
import
APScheduler
as
BaseAPScheduler
class
APScheduler
(
BaseAPScheduler
):
"""
A custom APScheduler with context management.
This allows the scheduler to work with Flask's application context,
which is necessary for tasks that interact with the database.
"""
def
run_job
(
self
,
_id
,
_job
=
None
):
"""
Run a job with Flask's application context.
:param _id: The ID of the job to run.
:param _job: The job store alias.
"""
with
self
.
app
.
app_context
():
super
().
run_job
(
id
=
_id
,
jobstore
=
_job
)
application/libs/tasks/__init__.py
View file @
d3969b3c
...
...
@@ -6,6 +6,8 @@
# @Author : StudentCWZ
# @Email : StudentCWZ@outlook.com
# @Date : 2023/11/7 16:16
# @File : __init__.py
.py
# @File : __init__.py
# @Description :
"""
from
.task
import
task
application/libs/tasks/task.py
View file @
d3969b3c
...
...
@@ -9,3 +9,12 @@
# @File : task.py
# @Description :
"""
def
task
():
"""
Some Tasks.
:return: None
"""
print
(
1
)
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