diff --git a/config.ini.example b/config.ini.example index 39f6de5..4a236f2 100644 --- a/config.ini.example +++ b/config.ini.example @@ -2,6 +2,7 @@ queue = /some/dir storage = /another/dir processing = /a/third/dir +error = /an/error_dir notify_url = https://example.com/api/notify notify_token = diff --git a/daemon/__init__.py b/daemon/__init__.py index 0cf5824..9335738 100644 --- a/daemon/__init__.py +++ b/daemon/__init__.py @@ -11,6 +11,7 @@ from pipeline import Pipeline class Daemon: def __init__(self, config): self.queue_dir = config['daemon']['queue'] + self.error_dir = config['daemon']['error'] self.logger = logging.getLogger('play-daemon') self.logger.setLevel('DEBUG') if 'mail_level' in config['daemon']: @@ -51,6 +52,10 @@ class Daemon: except Exception as e: msg = "Exception during processing of queue item %s: %s" self.logger.exception(msg, pres_id, queue_item, exc_info=e) + # write the que info and error to disk for play-api to display the status + with open(os.path.join(self.error_dir, pres_id), 'w') as f: + queue_item['error'] = e + json.dump(queue_item, f) class QueueUpdater(FileSystemEventHandler): diff --git a/daemon/pipeline.py b/daemon/pipeline.py index 3e1a740..c889762 100644 --- a/daemon/pipeline.py +++ b/daemon/pipeline.py @@ -14,6 +14,7 @@ class Pipeline: self.logger = logging.getLogger('play-daemon') self.queue = config['daemon']['queue'] self.storage = config['daemon']['storage'] + self.error = config['daemon']['error'] self.processing = config['daemon']['processing'] self.notify_url = config['daemon']['notify_url'] token = config['daemon']['notify_token'] @@ -168,6 +169,11 @@ class Pipeline: # Delete queue file and upload data os.remove(os.path.join(self.queue, target_id)) + try: + # if any old error file remove it since it worked + os.remove(os.path.join(self.error, target_id)) + except OSError: + pass shutil.rmtree(package['base']) return