BCDA-APS / bluesky_training

Bluesky training, including instrument package
https://bcda-aps.github.io/bluesky_training/
Other
12 stars 0 forks source link

switch to use tiled server #252

Open prjemian opened 1 year ago

prjemian commented 1 year ago

As noted in an hklpy issue, we need to switch our catalog reference to use tiled server:

from tiled.client import from_uri

# For security, set the API key by setting env var
# TILED_API_KEY rather than putting it in code.

URI = "http://localhost:8020"
client = from_uri(URI)
cat = client["training"]
RE = RunEngine()
# RE.subscribe(cat.v1.insert)  # the old way
RE.subscribe(cat.post_document)

Tiled docs have advice about creating/storing the API key.

We'll need instructions for routine installation of a tiled server for each instrument, and reconfiguration of the instrument package for this change.

Tasks for unit testing

prjemian commented 1 year ago

Follow similar activity in hklpy.

prjemian commented 1 year ago

CI workflow steps:

    - name: Checkout this repository
      uses: actions/checkout@v4

    - name: Start MongoDB
      uses: supercharge/mongodb-github-action@1.10.0

    - name: Start tiled server on host port 8019
      run: |
        docker pull ghcr.io/bluesky/tiled:main
        docker run \
          -d \
          --rm \
          -p 8019:8000 \
          -e TILED_SINGLE_USER_API_KEY=secret \
          ghcr.io/bluesky/tiled:main
prjemian commented 11 months ago

NOTE: needs apstools 1.6.19 (due by March 2024)

prjemian commented 11 months ago

Example python code to start a local (no network) tiled server with config for MongoDB server (which is network based):

from tiled.client import Context, from_context
from tiled.server.app import build_app_from_config

config = {
    "trees": [
        {
            "path": "bluesky_runs",
            "tree": "databroker.mongo_normalized:MongoAdapter.from_uri",
            "args": {"uri": "mongodb://localhost:27017/bluesky_runs"},
        }
    ]
}

app = build_app_from_config(config)
context = Context.from_app(app)
client = from_context(context)