Skip to content

Commit

Permalink
ver + changelog
Browse files Browse the repository at this point in the history
Signed-off-by: Ayush Kamat <ayush@latch.bio>
  • Loading branch information
ayushkamat committed Oct 11, 2024
1 parent d594b6a commit e299165
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ Types of changes

# Latch SDK Changelog

## 2.53.7 - 2024-10-11

### Added

* Nextflow
- add `latch attach` command to attach to a nextflow work directory

## 2.53.6 - 2024-10-11

### Added
Expand Down
31 changes: 28 additions & 3 deletions latch_cli/services/k8s/attach.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from typing import Optional
from urllib.parse import urljoin, urlparse

import click
import websockets.client as websockets
import websockets.exceptions as ws_exceptions
from latch_sdk_config.latch import NUCLEUS_URL

from latch_cli.services.k8s.utils import get_execution_info
Expand All @@ -16,20 +18,35 @@

async def connect(execution_id: str, session_id: str):
async with websockets.connect(
urlparse(urljoin(NUCLEUS_URL, "/workflows/cli/attach"))
urlparse(urljoin(NUCLEUS_URL, "/workflows/cli/attach-nf-workdir"))
._replace(scheme="wss")
.geturl(),
close_timeout=0,
extra_headers={"Authorization": get_auth_header()},
) as ws:
request = {"execution_id": execution_id, "session_id": session_id}
request = {"execution_id": int(execution_id), "session_id": session_id}

await ws.send(json.dumps(request))
data = await ws.recv()

msg = ""
try:
res = json.loads(data)
if "error" in res:
raise RuntimeError(res["error"])
except json.JSONDecodeError:
msg = "Unable to connect to pod - internal error."
except RuntimeError as e:
msg = str(e)

if msg != "":
raise RuntimeError(msg)

await forward_stdio(ws)


def get_session_id():
return secrets.token_bytes(18).hex()
return secrets.token_bytes(8).hex()


def attach(execution_id: Optional[str] = None):
Expand All @@ -42,7 +59,15 @@ def attach(execution_id: Optional[str] = None):
old_settings_stdin = termios.tcgetattr(sys.stdin.fileno())
tty.setraw(sys.stdin)

msg = ""
try:
asyncio.run(connect(execution_info["id"], session_id))
except ws_exceptions.ConnectionClosedError as e:
msg = json.loads(e.reason)["error"]
except RuntimeError as e:
msg = str(e)
finally:
termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, old_settings_stdin)

if msg != "":
click.secho(msg, fg="red")
15 changes: 15 additions & 0 deletions latch_cli/services/k8s/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ async def connect(egn_info: EGNNode, container_info: Optional[ContainerNode]):
}

await ws.send(json.dumps(request))
data = await ws.recv()

msg = ""
try:
res = json.loads(data)
if "error" in res:
raise RuntimeError(res["error"])
except json.JSONDecodeError:
msg = "Unable to connect to pod - internal error."
except RuntimeError as e:
msg = str(e)

if msg != "":
raise RuntimeError(msg)

await forward_stdio(ws)


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

setup(
name="latch",
version="v2.53.6",
version="v2.53.7",
author_email="kenny@latch.bio",
description="The Latch SDK",
packages=find_packages(),
Expand Down

0 comments on commit e299165

Please sign in to comment.