Skip to content

Commit

Permalink
refactor: move cleanup intervall to config variable
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasschaub committed Jul 16, 2024
1 parent f27db34 commit 3371a3f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions sketch_map_tool/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"user-agent": "sketch-map-tool",
"broker-url": "redis://localhost:6379",
"result-backend": "db+postgresql://smt:smt@localhost:5432",
"cleanup-map-frames-intervall": "12 months",
"wms-url-osm": "https://maps.heigit.org/osm-carto/service?SERVICE=WMS&VERSION=1.1.1",
"wms-layers-osm": "heigit:osm-carto@2xx",
"wms-url-esri-world-imagery": "https://maps.heigit.org/sketch-map-tool/service?SERVICE=WMS&VERSION=1.1.1",
Expand Down
6 changes: 4 additions & 2 deletions sketch_map_tool/database/client_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def cleanup_map_frames():
"""Cleanup map frames which are old and without consent.
Only set file to null. Keep metadata.
This function is called by a periodic celery task.
"""
query = """
UPDATE
Expand All @@ -119,7 +120,7 @@ def cleanup_map_frames():
file = NULL,
bbox = NULL
WHERE
ts < NOW() - INTERVAL '6 months'
ts < NOW() - INTERVAL %s
AND NOT EXISTS (
SELECT
*
Expand All @@ -131,7 +132,7 @@ def cleanup_map_frames():
"""
with db_conn.cursor() as curs:
try:
curs.execute(query)
curs.execute(query, [get_config_value("cleanup-map-frames-intervall")])
except UndefinedTable:
logging.info("Table `map_frame` does not exist yet. Nothing todo.")

Expand All @@ -140,6 +141,7 @@ def cleanup_blob(map_frame_uuids: list[UUID]):
"""Cleanup uploaded files (sketch maps) without consent.
Only set file and name to null. Keep metadata.
This function is called after digitization.
"""
query = """
UPDATE
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_database_client_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def map_frame_old(flask_app, uuid_create, map_frame, bbox):
# NOTE: Maybe mocking a map frame in the database with fake file
with flask_app.app_context():
update_query = (
"UPDATE map_frame SET ts = NOW() - INTERVAL '6 months' WHERE uuid = %s"
"UPDATE map_frame SET ts = NOW() - INTERVAL '12 months' WHERE uuid = %s"
)
with client_flask.open_connection().cursor() as curs:
curs.execute(update_query, [uuid_create])
Expand Down

0 comments on commit 3371a3f

Please sign in to comment.