From 06f6e6f2d31fe40a0812595379264509fc306147 Mon Sep 17 00:00:00 2001 From: daffyDukk Date: Tue, 26 Oct 2021 14:01:42 +0200 Subject: [PATCH 1/5] first iteration of errorhandling' --- config.ini.example | 1 + daemon/__init__.py | 4 ++++ 2 files changed, 5 insertions(+) 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..d2ed7c3 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,9 @@ 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) + 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): -- 2.39.5 From c0295203a746fcf04cf356f422774299172882f7 Mon Sep 17 00:00:00 2001 From: daffyDukk Date: Tue, 26 Oct 2021 14:18:56 +0200 Subject: [PATCH 2/5] cleaning up of old error files upon successfull completion of a job --- daemon/pipeline.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/daemon/pipeline.py b/daemon/pipeline.py index 3e1a740..f007ab9 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,7 @@ class Pipeline: # Delete queue file and upload data os.remove(os.path.join(self.queue, target_id)) + os.remove(os.path.join(self.error, target_id)) shutil.rmtree(package['base']) return -- 2.39.5 From 3f787ab5d05b103cdc34d6c2fe366a4b8a6bce57 Mon Sep 17 00:00:00 2001 From: daffyDukk Date: Tue, 26 Oct 2021 14:29:26 +0200 Subject: [PATCH 3/5] added handling of non existant error files --- daemon/pipeline.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/daemon/pipeline.py b/daemon/pipeline.py index f007ab9..5acf20c 100644 --- a/daemon/pipeline.py +++ b/daemon/pipeline.py @@ -169,7 +169,10 @@ class Pipeline: # Delete queue file and upload data os.remove(os.path.join(self.queue, target_id)) - os.remove(os.path.join(self.error, target_id)) + try: + os.remove(os.path.join(self.error, target_id)) + except OSError: + pass shutil.rmtree(package['base']) return -- 2.39.5 From ec549a99b4c7266c25bed1f0ba7371869a4d6007 Mon Sep 17 00:00:00 2001 From: daffyDukk Date: Tue, 26 Oct 2021 15:38:43 +0200 Subject: [PATCH 4/5] comments --- daemon/__init__.py | 1 + daemon/pipeline.py | 1 + 2 files changed, 2 insertions(+) diff --git a/daemon/__init__.py b/daemon/__init__.py index d2ed7c3..9335738 100644 --- a/daemon/__init__.py +++ b/daemon/__init__.py @@ -52,6 +52,7 @@ 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) diff --git a/daemon/pipeline.py b/daemon/pipeline.py index 5acf20c..9687eb1 100644 --- a/daemon/pipeline.py +++ b/daemon/pipeline.py @@ -170,6 +170,7 @@ 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 now iot has worked os.remove(os.path.join(self.error, target_id)) except OSError: pass -- 2.39.5 From ad9583aa10e712770d48afabd4edfaa5dcd676d4 Mon Sep 17 00:00:00 2001 From: daffyDukk Date: Tue, 26 Oct 2021 15:59:04 +0200 Subject: [PATCH 5/5] comments --- daemon/pipeline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daemon/pipeline.py b/daemon/pipeline.py index 9687eb1..c889762 100644 --- a/daemon/pipeline.py +++ b/daemon/pipeline.py @@ -170,7 +170,7 @@ 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 now iot has worked + # if any old error file remove it since it worked os.remove(os.path.join(self.error, target_id)) except OSError: pass -- 2.39.5