Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
StorageLeaf
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ProjectLeaf
StorageLeaf
Commits
b18c00d3
Commit
b18c00d3
authored
3 years ago
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
#9 - call database cleaner
parent
ce8985eb
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
settings-example.json
+11
-1
11 additions, 1 deletion
settings-example.json
src/logic/database/DatabaseCleaner.py
+28
-0
28 additions, 0 deletions
src/logic/database/DatabaseCleaner.py
src/logic/routers/GeneralRouter.py
+8
-2
8 additions, 2 deletions
src/logic/routers/GeneralRouter.py
with
47 additions
and
3 deletions
settings-example.json
+
11
−
1
View file @
b18c00d3
...
@@ -20,7 +20,17 @@
...
@@ -20,7 +20,17 @@
"owncloudUser"
:
"myUser"
,
"owncloudUser"
:
"myUser"
,
"owncloudPassword"
:
""
,
"owncloudPassword"
:
""
,
"owncloudDestinationPath"
:
"MyFolder"
"owncloudDestinationPath"
:
"MyFolder"
},
"retentionPolicies"
:
[
{
"resolutionInMinutes"
:
60
,
"ageInDays"
:
30
},
{
"resolutionInMinutes"
:
3600
,
"ageInDays"
:
60
}
}
]
},
},
"api"
:
{
"api"
:
{
"url"
:
"http://localhost:10003"
,
"url"
:
"http://localhost:10003"
,
...
...
This diff is collapsed.
Click to expand it.
src/logic/database/DatabaseCleaner.py
0 → 100644
+
28
−
0
View file @
b18c00d3
import
logging
from
dataclasses
import
dataclass
from
typing
import
List
from
sqlalchemy.orm
import
Session
from
logic
import
Constants
LOGGER
=
logging
.
getLogger
(
Constants
.
APP_NAME
)
@dataclass
class
RetentionPolicy
:
resolutionInMinutes
:
int
ageInDays
:
int
class
DatabaseCleaner
:
def
__init__
(
self
,
retentionPolicies
:
List
[
RetentionPolicy
]):
self
.
_policies
=
retentionPolicies
def
clean
(
self
,
db
:
Session
):
LOGGER
.
info
(
'
Performing database cleanup...
'
)
for
policy
in
self
.
_policies
:
LOGGER
.
debug
(
f
'
Enforcing retention policy:
{
policy
}
'
)
LOGGER
.
info
(
'
Database cleanup done
'
)
This diff is collapsed.
Click to expand it.
src/logic/routers/GeneralRouter.py
+
8
−
2
View file @
b18c00d3
from
fastapi
import
APIRouter
,
Depends
from
fastapi
import
APIRouter
,
Depends
from
sqlalchemy.orm
import
Session
from
sqlalchemy.orm
import
Session
from
Settings
import
VERSION
from
Settings
import
VERSION
,
SETTINGS
from
logic.Dependencies
import
get_database
from
logic.Dependencies
import
get_database
from
logic.database
import
Schemas
,
DatabaseInfoProvider
from
logic.database
import
Schemas
,
DatabaseInfoProvider
from
logic.database.DatabaseCleaner
import
DatabaseCleaner
,
RetentionPolicy
router
=
APIRouter
(
router
=
APIRouter
(
prefix
=
'
/general
'
,
prefix
=
'
/general
'
,
...
@@ -31,7 +32,12 @@ async def databaseInfo(db: Session = Depends(get_database)):
...
@@ -31,7 +32,12 @@ async def databaseInfo(db: Session = Depends(get_database)):
async
def
databaseCleanup
(
db
:
Session
=
Depends
(
get_database
)):
async
def
databaseCleanup
(
db
:
Session
=
Depends
(
get_database
)):
infoBefore
=
DatabaseInfoProvider
.
get_database_info
(
db
)
infoBefore
=
DatabaseInfoProvider
.
get_database_info
(
db
)
# TODO
retentionPolicies
=
SETTINGS
[
'
database
'
][
'
retentionPolicies
'
]
policies
=
[]
for
item
in
retentionPolicies
:
policies
.
append
(
RetentionPolicy
(
resolutionInMinutes
=
item
[
'
resolutionInMinutes
'
],
ageInDays
=
item
[
'
ageInDays
'
]))
DatabaseCleaner
(
policies
).
clean
(
db
)
infoAfter
=
DatabaseInfoProvider
.
get_database_info
(
db
)
infoAfter
=
DatabaseInfoProvider
.
get_database_info
(
db
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment