Skip to content

Commit

Permalink
Add a is_running function to the endpoint API and use it for starting…
Browse files Browse the repository at this point in the history
… meps
  • Loading branch information
christopherwharrop-noaa committed Nov 28, 2024
1 parent a9e5d95 commit 9809a8b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
33 changes: 33 additions & 0 deletions src/chiltepin/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import subprocess
import sys
import time
from typing import Dict

import yaml
Expand Down Expand Up @@ -246,6 +247,34 @@ def list(config_dir: str | None = None, timeout: int = 60) -> Dict[str, str]:
return ep_list


def is_running(name: str, config_dir: str | None = None) -> bool:
"""Return True if the endpoint is running, otherwise False
Parameters
----------
name: str
Name of the endpoint to check
config_dir: str | None
Path to endpoint configuration directory where endpoint information
is stored. If None (the default), then $HOME/.globus_compute is used
Returns
-------
bool
"""
# Get a list of endpoints
ep_list = list(config_dir)

# Get the endpoint info
ep_info = ep_list.get(name, {})

# Return whether endpoint state is "Running"
return ep_info.get("state", None) == "Running"


def start(name: str, config_dir: str | None = None, timeout: int = 60):
"""Start the specified Globus Compute Endpoint
Expand Down Expand Up @@ -289,6 +318,10 @@ def start(name: str, config_dir: str | None = None, timeout: int = 60):
# Write the pid to the endpoint pid file
with open(config_path / "daemon.pid", "w") as f:
f.write(f"{p.pid}\n")
# Wait for endpoint to enter "Running" state
while not is_running(name, config_dir):
time.sleep(1)

else:
# Run the command as a normal subprocess
p = subprocess.run(
Expand Down
3 changes: 0 additions & 3 deletions tests/test_endpoint_mep.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import pathlib
import shutil
import time

import chiltepin.endpoint as endpoint

Expand Down Expand Up @@ -63,8 +62,6 @@ def test_endpoint_start():
endpoint.start("foo")
# Start an endpoint with a config_dir
endpoint.start("bar", config_dir=f"{pwd}/.globus_compute")
# Wait a few seconds for the endpoints to get started
time.sleep(3)
# Verify they are running
ep_list = endpoint.list()
assert ep_list["foo"]["state"] == "Running"
Expand Down
4 changes: 0 additions & 4 deletions tests/test_globus_compute_mep_hello.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pathlib
import time

import parsl
import pytest
Expand Down Expand Up @@ -32,9 +31,6 @@ def config(config_file, platform):
# Start the test endpoint
endpoint.start("test", config_dir=f"{pwd}/.globus_compute")

# Wait a few seconds for the mep to start up
time.sleep(5)

# Update resource config with the test endpoint id
resource_config = _set_endpoint_ids(resource_config)

Expand Down
4 changes: 0 additions & 4 deletions tests/test_globus_compute_mep_mpi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os.path
import pathlib
import re
import time
from datetime import datetime as dt

import parsl
Expand Down Expand Up @@ -38,9 +37,6 @@ def config(config_file, platform):
# Start the test endpoint
endpoint.start("test", config_dir=f"{pwd}/.globus_compute")

# Wait a few seconds for the endpoint to be ready
time.sleep(3)

# Update resource config with the test endpoint ids
resource_config = _set_endpoint_ids(resource_config)

Expand Down

0 comments on commit 9809a8b

Please sign in to comment.