mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-11-11 17:16:43 -05:00
Cleanup expired task
This commit is contained in:
parent
af59678224
commit
80d8f377d3
@ -658,3 +658,26 @@ def build_share_bundle(bundle_id: int):
|
|||||||
temp_zip_path.unlink()
|
temp_zip_path.unlink()
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@shared_task
|
||||||
|
def cleanup_expired_share_bundles():
|
||||||
|
now = timezone.now()
|
||||||
|
expired_qs = ShareBundle.objects.filter(
|
||||||
|
deleted_at__isnull=True,
|
||||||
|
expiration__isnull=False,
|
||||||
|
expiration__lt=now,
|
||||||
|
)
|
||||||
|
count = 0
|
||||||
|
for bundle in expired_qs.iterator():
|
||||||
|
count += 1
|
||||||
|
try:
|
||||||
|
bundle.hard_delete()
|
||||||
|
except Exception as exc:
|
||||||
|
logger.warning(
|
||||||
|
"Failed to delete expired share bundle %s: %s",
|
||||||
|
bundle.pk,
|
||||||
|
exc,
|
||||||
|
)
|
||||||
|
if count:
|
||||||
|
logger.info("Deleted %s expired share bundle(s)", count)
|
||||||
|
|||||||
@ -230,6 +230,17 @@ def _parse_beat_schedule() -> dict:
|
|||||||
"expires": 59.0 * 60.0,
|
"expires": 59.0 * 60.0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "Cleanup expired share bundles",
|
||||||
|
"env_key": "PAPERLESS_SHARE_BUNDLE_CLEANUP_CRON",
|
||||||
|
# Default daily at 02:00
|
||||||
|
"env_default": "0 2 * * *",
|
||||||
|
"task": "documents.tasks.cleanup_expired_share_bundles",
|
||||||
|
"options": {
|
||||||
|
# 1 hour before default schedule sends again
|
||||||
|
"expires": 23.0 * 60.0 * 60.0,
|
||||||
|
},
|
||||||
|
},
|
||||||
]
|
]
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
# Either get the environment setting or use the default
|
# Either get the environment setting or use the default
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user