Skip to content

Commit

Permalink
refactor(cleanup): remove uuid argument
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasschaub committed Jun 11, 2024
1 parent f1cc306 commit adf3e6a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
12 changes: 5 additions & 7 deletions sketch_map_tool/database/client_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,18 @@ def delete_map_frame(uuid: UUID):
curs.execute(query, [str(uuid)])


def set_map_frame_to_null(uuid: UUID):
"""Set map frame of the associated UUID from the database to null.
def cleanup_map_frames():
"""Cleanup map frames which are old or do not have a consent by the user.
Keep UUID and timestamp in the database.
Only set file to null. Keep metadata.
"""
# TODO: JOIN with blog to read consent
query = """
UPDATE
map_frame
SET
file = NULL
WHERE
uuid = %s
AND ts < NOW() - INTERVAL '6 months'
ts < NOW() - INTERVAL '6 months'
AND NOT EXISTS (
SELECT
*
Expand All @@ -78,7 +76,7 @@ def set_map_frame_to_null(uuid: UUID):
AND consent = TRUE);
"""
with db_conn.cursor() as curs:
curs.execute(query, [str(uuid)])
curs.execute(query)


def select_file(id_: int) -> bytes:
Expand Down
4 changes: 2 additions & 2 deletions sketch_map_tool/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,6 @@ def digitize_sketches(


@celery.task
def cleanup(uuid):
def cleanup():
"""Clean up"""
db_client_celery.set_map_frame_to_null(uuid)
db_client_celery.cleanup_map_frames()
4 changes: 2 additions & 2 deletions tests/integration/test_celery_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_generate_quality_report(bbox_wgs84):
@pytest.mark.usefixtures("uuid_digitize")
def test_cleanup_nothing_to_do(uuid_create, flask_app):
with flask_app.app_context():
task = tasks.cleanup.apply_async(args=[uuid_create])
task = tasks.cleanup.apply_async()
task.wait()
# should not raise an error
result = select_map_frame(UUID(uuid_create))
Expand All @@ -67,7 +67,7 @@ def test_cleanup_old_map_frame(uuid_create, flask_app):
db_conn = open_connection()
with db_conn.cursor() as curs:
curs.execute(update_query, [uuid_create])
task = tasks.cleanup.apply_async(args=[uuid_create])
task = tasks.cleanup.apply_async()
task.wait()
with pytest.raises(CustomFileDoesNotExistAnymoreError):
select_map_frame(UUID(uuid_create))
Expand Down

0 comments on commit adf3e6a

Please sign in to comment.