diff --git a/VERSION b/VERSION index 5cc4e72..870328a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -master-v0.9 \ No newline at end of file +master-v0.9.1 \ No newline at end of file diff --git a/flows/api/__init__.py b/flows/api/__init__.py index dbcdd0f..8ad4638 100644 --- a/flows/api/__init__.py +++ b/flows/api/__init__.py @@ -7,6 +7,6 @@ from .catalogs import get_catalog, get_catalog_missing from .sites import get_site, get_all_sites from .photometry_api import get_photometry, upload_photometry -from .set_photometry_status import set_photometry_status +from .set_photometry_status import set_photometry_status, cleanup_photometry_status from .filters import get_filters from .lightcurves import get_lightcurve diff --git a/flows/api/set_photometry_status.py b/flows/api/set_photometry_status.py index 3aeb3be..b0fc572 100644 --- a/flows/api/set_photometry_status.py +++ b/flows/api/set_photometry_status.py @@ -48,3 +48,39 @@ def set_photometry_status(fileid, status): raise RuntimeError(res) return True + +#-------------------------------------------------------------------------------------------------- +def cleanup_photometry_status(): + """ + Perform a cleanup of the photometry status indicator. + + This will change all processes still marked as "running" + to "abort" if they have been running for more than a day. + + .. codeauthor:: Rasmus Handberg + """ + # Validate the input: + logger = logging.getLogger(__name__) + + # Get API token from config file: + config = load_config() + i_am_pipeline = config.getboolean('api', 'pipeline', fallback=False) + if not i_am_pipeline: + logger.debug("Not setting status since user is not pipeline") + return False + + # Get API token from config file: + token = config.get('api', 'token', fallback=None) + if token is None: + raise RuntimeError("No API token has been defined") + + # Send HTTP request to FLOWS server: + r = requests.get('https://flows.phys.au.dk/api/cleanup_photometry_status.php', + headers={'Authorization': 'Bearer ' + token}) + r.raise_for_status() + res = r.text.strip() + + if res != 'OK': + raise RuntimeError(res) + + return True diff --git a/run_photometry.py b/run_photometry.py index 1c7cac4..4614a6b 100644 --- a/run_photometry.py +++ b/run_photometry.py @@ -128,6 +128,13 @@ def main(): logger.propagate = False logger.setLevel(logging_level) + # If we have started a new processing, perform a cleanup of the + # photometry status indicator. This will change all processes + # still marked as "running" to "abort" if they have been running + # for more than a day: + if args.autoupload: + api.cleanup_photometry_status() + if args.fileid is not None: # Run the specified fileids: fileids = args.fileid