-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch from bypass to TESTING_INSTANCE in config.
- Loading branch information
Showing
8 changed files
with
105 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""This is used only if config.TESTING_INSTANCE is True, and is | ||
used to remove old articles. | ||
""" | ||
|
||
from datetime import datetime, timedelta | ||
from pathlib import Path | ||
import shutil | ||
|
||
from sqlalchemy import create_engine, select | ||
from sqlalchemy.orm import Session | ||
from . import scheduler | ||
from .metadata.db_models import PaperStatus | ||
|
||
def cleanup_task(): | ||
with scheduler.app.app_context(): | ||
if scheduler.app.config['DEBUG']: | ||
scheduler.app.logger.warning('skipping cleanup of existing papers') | ||
return | ||
if scheduler.app.config['TESTING_INSTANCE']: | ||
scheduler.app.logger.warning('cleanup should not be configured') | ||
return | ||
scheduler.app.logger.warning('cleaning up papers') | ||
submit_deadline = datetime.now() - timedelta(days=1) | ||
copyedit_deadline = datetime.now() - timedelta(days=4) | ||
engine = create_engine(scheduler.app.config['SQLALCHEMY_DATABASE_URI']) | ||
deleted_ids = set() | ||
with Session(engine) as session: | ||
papers = session.execute(select(PaperStatus)).scalars().all() | ||
for paper in papers: | ||
if paper.status == PaperStatus.PENDING.value and paper.lastmodified < submit_deadline: | ||
deleted_ids.add(paper.paperid) | ||
session.delete(paper) | ||
elif paper.lastmodified < copyedit_deadline: | ||
deleted_ids.add(paper.paperid) | ||
session.delete(paper) | ||
session.commit() | ||
engine.dispose(True) | ||
for paperid in deleted_ids: | ||
dir = Path(scheduler.app.config['DATA_DIR']) / Path(paperid) | ||
try: | ||
shutil.rmtree(dir) | ||
scheduler.app.logger.warning('Deleted {}'.format(dir.name)) | ||
except Exception as e: | ||
scheduler.app.logger.warning('Unable to delete the directory for the paper {}. ({})'.format(str(dir.absolute()), str(e))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,3 +54,4 @@ requests | |
docker | ||
markdown | ||
pymemcache | ||
apscheduler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters