Skip to content

Commit

Permalink
Pull etag before atempting update
Browse files Browse the repository at this point in the history
  • Loading branch information
zwolf committed May 29, 2024
1 parent d4635b9 commit 194b0ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
19 changes: 10 additions & 9 deletions panoptes_aggregation/batch_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ def run_aggregation(project_id, workflow_id, user_id):
reduced_data[reducer].to_csv(filename, mode='a')
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()
ba.update_panoptes()


class BatchAggregator:
Expand Down Expand Up @@ -117,17 +116,19 @@ 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(
def update_panoptes(self):
# An Aggregation class can be added to the python client to avoid doing this manually
params = {'workflow_id': self.workflow_id, 'user_id': self.user_id}
response = Panoptes.client().get('/aggregations/', params=params)
fresh_etag = response[1]

Panoptes.client().put(
'/aggregations/',
etag=fresh_etag,
json={
'aggregations': {
'uuid': self.id,
'status': 'completed',
'links': {
'workflow': self.workflow_id,
'user': self.user_id
}
'status': 'completed'
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ 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):
@patch("panoptes_aggregation.batch_aggregation.Panoptes.put")
@patch("panoptes_aggregation.batch_aggregation.Panoptes.get")
def test_update_panoptes(self, mock_get, mock_put):
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}}})
mock_get.return_value = ({}, 'thisisanetag')
ba.update_panoptes()
mock_get.assert_called_with('/aggregations/', params={'workflow_id': 10, 'user_id': 100})
mock_put.assert_called_with('/aggregations/', etag='thisisanetag', json={'aggregations': {'uuid': ba.id, 'status': 'completed'}})

@patch("panoptes_aggregation.batch_aggregation.BlobServiceClient")
def test_connect_blob_storage(self, mock_client):
Expand Down

0 comments on commit 194b0ae

Please sign in to comment.