-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
134a554
commit ae63e23
Showing
9 changed files
with
185 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
stomp: | ||
host: "localhost" | ||
port: 61613 | ||
auth: | ||
username: "guest" | ||
password: "guest" | ||
# New config | ||
numtracker: | ||
url: https://numtracker.diamond.ac.uk/graphql | ||
env: | ||
# New config | ||
metadata: | ||
data_session: cm37271-2 | ||
instrument: i22 | ||
oidc: | ||
well_known_url: "https://authn.diamond.ac.uk/realms/master/.well-known/openid-configuration" | ||
client_id: "blueapi-cli" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
stomp: | ||
host: "localhost" | ||
port: 61613 | ||
auth: | ||
username: "guest" | ||
password: "guest" | ||
numtracker: | ||
url: http://localhost:8002/graphql | ||
env: | ||
metadata: | ||
data_session: cm123456 | ||
instrument: i22 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import logging | ||
from collections.abc import Mapping | ||
from pathlib import Path | ||
|
||
import requests | ||
from pydantic import Field | ||
|
||
from blueapi.utils import BlueapiBaseModel | ||
|
||
|
||
class NumtrackerNewScanVisit(BlueapiBaseModel): | ||
beamline: str | ||
directory: Path | ||
|
||
|
||
class NumtrackerNewScanScan(BlueapiBaseModel): | ||
scan_file: str = Field(alias="scanFile") | ||
scan_number: int = Field(alias="scanNumber") | ||
visit: NumtrackerNewScanVisit | ||
|
||
|
||
class NumtrackerNewScan(BlueapiBaseModel): | ||
scan: NumtrackerNewScanScan | ||
|
||
|
||
class NumtrackerClient: | ||
def __init__( | ||
self, | ||
url: str, | ||
headers: Mapping[str, str], | ||
) -> None: | ||
self._url = url | ||
self._headers = headers | ||
|
||
# TODO: Could make this async, but since it's called from RE.scan_id_source, we would need | ||
# to change the RE to accept an async function in the scan_id_source hook. It's a 1-line | ||
# change but would need to be reviewed etc. | ||
def create_scan(self, visit: str, beamline: str) -> NumtrackerNewScan: | ||
query = { | ||
"query": f'mutation{{scan(beamline: "{beamline}", visit: "{visit}") {{scanFile scanNumber visit{{beamline directory}}}}}}' | ||
} | ||
|
||
response = requests.post( | ||
self._url, | ||
headers=self._headers, | ||
json=query, | ||
) | ||
|
||
response.raise_for_status() | ||
json = response.json() | ||
|
||
if json["data"] is not None: | ||
new_collection = NumtrackerNewScan.model_validate(json["data"]) | ||
logging.debug("New NumtrackerNewScan: %s", new_collection) | ||
return new_collection | ||
else: | ||
error_message = json.get("errors", "unknown server error") | ||
raise RuntimeError(error_message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters