From 1f8b51ffff22b0123299283c1e9a5bf8690c946e Mon Sep 17 00:00:00 2001 From: Zach Wolfenbarger Date: Tue, 28 May 2024 18:29:30 -0500 Subject: [PATCH] Add final POST message to Panoptes --- panoptes_aggregation/batch_aggregation.py | 18 ++++++++++++++++++ .../test_batch_aggregation.py | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/panoptes_aggregation/batch_aggregation.py b/panoptes_aggregation/batch_aggregation.py index bf7f3c96..fe12ab42 100644 --- a/panoptes_aggregation/batch_aggregation.py +++ b/panoptes_aggregation/batch_aggregation.py @@ -51,6 +51,9 @@ def run_aggregation(project_id, workflow_id, user_id): ba.upload_files() # hit up panoptes, let em know you're done + # This could catch PanoptesAPIException, but what to do if it fails? + ba.create_run_in_panoptes() + class BatchAggregator: @@ -115,6 +118,21 @@ def upload_files(self): zipfile = make_archive(f'tmp/{self.id}', 'zip', self.output_path) self.upload_file_to_storage(self.id, zipfile) + def create_run_in_panoptes(self): + Panoptes.client().post( + '/aggregations/', + json={ + 'aggregations': { + 'uuid': self.id, + 'status': 'completed', + 'links': { + 'workflow': self.workflow_id, + 'user': self.user_id + } + } + } + ) + def _generate_uuid(self): self.id = uuid.uuid4().hex diff --git a/panoptes_aggregation/tests/batch_aggregation/test_batch_aggregation.py b/panoptes_aggregation/tests/batch_aggregation/test_batch_aggregation.py index 56ee9e08..e7b4efe9 100644 --- a/panoptes_aggregation/tests/batch_aggregation/test_batch_aggregation.py +++ b/panoptes_aggregation/tests/batch_aggregation/test_batch_aggregation.py @@ -108,6 +108,12 @@ def test_upload_file_to_storage(self): ba.upload_file_to_storage('container', cls_export) mock_client.upload_blob.assert_called_once + @patch("panoptes_aggregation.batch_aggregation.Panoptes.post") + def test_create_run_in_panoptes(self, mock_poster): + ba = batch_agg.BatchAggregator(1, 10, 100) + ba.create_run_in_panoptes() + mock_poster.assert_called_with('/aggregations/', json={ 'aggregations': { 'uuid': ba.id, 'status': 'completed', 'links': { 'workflow': 10, 'user': 100 } } }) + @patch("panoptes_aggregation.batch_aggregation.BlobServiceClient") def test_connect_blob_storage(self, mock_client): ba = batch_agg.BatchAggregator(1, 10, 100)