mirror of
https://github.com/simple-login/app.git
synced 2024-11-16 00:48:32 +01:00
0da1811311
* Cleanup tasks * Update * Added tests * Create cron job * Delete old data cron * Fix import * import fix * Added delete + script to disable pgp for proton mboxes
24 lines
661 B
Python
24 lines
661 B
Python
import arrow
|
|
from sqlalchemy import or_, and_
|
|
|
|
from app import config
|
|
from app.db import Session
|
|
from app.log import LOG
|
|
from app.models import Job, JobState
|
|
|
|
|
|
def cleanup_old_jobs(oldest_allowed: arrow.Arrow):
|
|
LOG.i(f"Deleting jobs older than {oldest_allowed}")
|
|
count = Job.filter(
|
|
or_(
|
|
Job.state == JobState.done.value,
|
|
Job.state == JobState.error.value,
|
|
and_(
|
|
Job.state == JobState.taken.value,
|
|
Job.attempts >= config.JOB_MAX_ATTEMPTS,
|
|
),
|
|
),
|
|
Job.updated_at < oldest_allowed,
|
|
).delete()
|
|
Session.commit()
|
|
LOG.i(f"Deleted {count} jobs")
|