Skip to content

Commit

Permalink
fix: Panoptes --wms-monitor-arg (#2444)
Browse files Browse the repository at this point in the history
### Description

This PR fix panoptes --wms-monitor-arg snakemake option.
--wms-monitor-arg was then not being processed by the requests, it is
now possible to change the name of the run using `--wms-monitor-arg
name=TEST_RUN` in the panoptes DB.

### QC
<!-- Make sure that you can tick the boxes below. -->

* [x] The PR contains a test case for the changes or the changes are
already covered by an existing test case.
* [x] The documentation (`docs/`) is updated to reflect the changes or
this is not necessary (e.g. if the change does neither modify the
language nor the behavior or functionalities of Snakemake).

---------

Co-authored-by: Filipe G. Vieira <1151762+fgvieira@users.noreply.github.com>
Co-authored-by: Johannes Köster <johannes.koester@tu-dortmund.de>
  • Loading branch information
3 people committed Nov 27, 2023
1 parent 1d58120 commit 98d2bdf
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions snakemake/logging.py
Expand Up @@ -134,7 +134,9 @@ def __init__(self, address=None, args=None, metadata=None):
from snakemake.resources import DefaultResources

self.address = address or "http:127.0.0.1:5000"
self.args = map(DefaultResources.decode_arg, args) if args else []
self.args = list(map(DefaultResources.decode_arg, args)) if args else []
self.args = {item[0]: item[1] for item in list(self.args)}

self.metadata = metadata or {}

# A token is suggested but not required, depends on server
Expand Down Expand Up @@ -190,22 +192,40 @@ def create_workflow(self):
f"{self.address}/create_workflow",
headers=self._headers,
params=self.args,
data=json.dumps(metadata),
data=metadata,
)

# Extract the id from the response
id = response.json()["id"]

# Check the response, will exit on any error
self.check_response(response, "/create_workflow")

# Provide server parameters to the logger
self.server = {"url": self.address, "id": response.json()["id"]}
headers = (
{"Content-Type": "application/json"}
if self._headers is None
else {**self._headers, **{"Content-Type": "application/json"}}
)

# Send the workflow name to the server
response_change_workflow_name = requests.put(
f"{self.address }/api/workflow/{id}",
headers=headers,
data=json.dumps(self.args),
)
# Check the response, will exit on any error
self.check_response(response_change_workflow_name, f"/api/workflow/{id}")

# Provide server parameters to the logger
self.server = {"url": self.address, "id": id}

def check_response(self, response, endpoint="wms monitor request"):
"""A helper function to take a response and check for an expected set of
error codes, 404 (not found), 401 (requires authorization), 403 (permission
denied), 500 (server error) and 200 (success).
"""
status_code = response.status_code

# Cut out early on success
if status_code == 200:
return
Expand Down Expand Up @@ -281,9 +301,7 @@ def log_handler(self, msg):
"timestamp": time.asctime(),
"id": self.server["id"],
}
response = requests.post(
url, data=json.dumps(server_info), headers=self._headers
)
response = requests.post(url, data=server_info, headers=self._headers)
self.check_response(response, "/update_workflow_status")


Expand Down

0 comments on commit 98d2bdf

Please sign in to comment.