Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Dockerfiles
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Picasoft
Technique
Dockerfiles
Commits
8715e365
Verified
Commit
8715e365
authored
4 years ago
by
Romain De Laage De Bellefaye
Browse files
Options
Downloads
Patches
Plain Diff
[CodiMD] Improve script
parent
46384f35
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pica-codimd/deleteOldPad.py
+22
-9
22 additions, 9 deletions
pica-codimd/deleteOldPad.py
with
22 additions
and
9 deletions
pica-codimd/deleteOldPad.py
+
22
−
9
View file @
8715e365
...
...
@@ -8,11 +8,12 @@ INTERVAL = environ['OLD_INTERVAL']
USER
=
environ
[
'
POSTGRES_USER
'
]
DATABASE
=
environ
[
'
POSTGRES_DB
'
]
PASSWORD
=
environ
[
'
POSTGRES_PASSWORD
'
]
HOST
=
[
'
DB_HOST
'
]
PORT
=
[
'
DB_PORT
'
]
HOST
=
environ
[
'
DB_HOST
'
]
PORT
=
environ
[
'
DB_PORT
'
]
print
(
"
===== Begin of deleteOldPad job =====
"
)
#Connect to database
try
:
db
=
psycopg2
.
connect
(
"
user =
"
+
USER
+
"
dbname =
"
+
DATABASE
+
"
password =
"
+
PASSWORD
+
"
host =
"
+
HOST
+
"
port =
"
+
PORT
)
except
:
...
...
@@ -20,20 +21,32 @@ except:
with
db
:
with
db
.
cursor
()
as
cur
:
#
Make a backup of old pads in deletedPads
#
Get all pads older than INTERVAL
try
:
cur
.
execute
(
"
SELECT
\"
Notes
\"
.
\"
id
\"
,
\"
Notes
\"
.
\"
content
\"
FROM
\"
Notes
\"
WHERE
\"
Notes
\"
.
\"
updatedAt
\"
< NOW() - interval %s
"
,
(
INTERVAL
,))
except
:
sys
.
exit
(
"
deleteOldPad : unable to select old pads
"
)
for
oldPad
in
cur
.
fetchall
():
oldPads
=
cur
.
fetchall
()
for
oldPad
in
oldPads
:
#Backup the pad
with
open
(
"
deletedPads/
"
+
oldPad
[
0
]
+
'
.txt
'
,
"
w
"
)
as
f
:
f
.
write
(
oldPad
[
1
])
#Remove all Revisions related to this pad
try
:
cur
.
execute
(
"
DELETE FROM
\"
Revisions
\"
WHERE
\"
Revisions
\"
.
\"
noteId
\"
= %s
"
,
(
oldPad
[
0
],))
except
:
sys
.
exit
(
"
deleteOldPad : unable to delete all revisions related to pad
"
+
oldPad
[
0
])
#Remove all contributions related to this pad
try
:
cur
.
execute
(
"
DELETE FROM
\"
Authors
\"
WHERE
\"
Authors
\"
.
\"
noteId
\"
= %s
"
,
(
oldPad
[
0
],))
except
:
sys
.
exit
(
"
deleteOldPad : unable to delete all contributions related to pad
"
+
oldPad
[
0
])
#Remove the pad
try
:
cur
.
execute
(
"
DELETE FROM
\"
Notes
\"
WHERE
\"
Notes
\"
.
\"
id
\"
= %s
"
,
(
oldPad
[
0
],))
except
:
sys
.
exit
(
"
deleteOldPad : unable to delete the pad
"
+
oldPad
[
0
])
#Delete the old pads
try
:
cur
.
execute
(
"
DELETE FROM
\"
Notes
\"
WHERE
\"
Notes
\"
.
\"
updatedAt
\"
< NOW() - interval %s
"
,
(
INTERVAL
,))
except
:
sys
.
exit
(
"
deleteOldPad: unable to delete old pads
"
)
print
(
"
deleteOldPad : Deleted old pad
"
)
db
.
close
()
...
...
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