Skip to content

Commit

Permalink
Don't exit process if a function fails (#187)
Browse files Browse the repository at this point in the history
- Don't exit process if a function fails
- Fix volume http routes

---------

Co-authored-by: Luke Lombardi <[email protected]>
  • Loading branch information
luke-lombardi and Luke Lombardi authored May 3, 2024
1 parent dfd1804 commit d52202e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
21 changes: 7 additions & 14 deletions internal/abstractions/volume/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ func registerVolumeRoutes(g *echo.Group, gvs *GlobalVolumeService) *volumeGroup
group := &volumeGroup{routeGroup: g, gvs: gvs}

g.GET("/:workspaceId", group.ListVolumes)
g.GET("/:workspaceId/", group.ListVolumes)

g.POST("/:workspaceId/:volumeName", group.CreateVolume)
g.POST("/:workspaceId/:volumeName/", group.CreateVolume)

g.GET("/:workspaceId/:volumeName/*", group.Ls)
g.DELETE("/:workspaceId/:volumeName/*", group.Rm)
g.PATCH("/:workspaceId/:volumeName/*", group.Mv)
g.GET("/:workspaceId/:volumePath*", group.Ls)
g.DELETE("/:workspaceId/:volumePath*", group.Rm)
g.PATCH("/:workspaceId/:volumePath*", group.Mv)

return group
}
Expand Down Expand Up @@ -92,12 +89,10 @@ func (g *volumeGroup) Ls(ctx echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid workspace ID")
}

volumeName := ctx.Param("volumeName")
path := ctx.Param("*")

volumePath := ctx.Param("volumePath*")
if paths, err := g.gvs.listPath(
ctx.Request().Context(),
volumeName+"/"+path,
volumePath,
&workspace,
); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to list path")
Expand All @@ -118,12 +113,10 @@ func (g *volumeGroup) Rm(ctx echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid workspace ID")
}

volumeName := ctx.Param("volumeName")
path := ctx.Param("*")

volumePath := ctx.Param("volumePath*")
if _, err := g.gvs.deletePath(
ctx.Request().Context(),
volumeName+"/"+path,
volumePath,
&workspace,
); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to delete path")
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/beta9/abstractions/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ async def _call_remote(self, *args, **kwargs) -> Any:
break

if last_response is None or not last_response.done or last_response.exit_code != 0:
terminal.error("Function failed ☠️")
return None
terminal.error(f"Function failed <{last_response.task_id}> ☠️", exit=False)
return

terminal.header(f"Function complete <{last_response.task_id}>")
return cloudpickle.loads(last_response.result)
Expand Down
6 changes: 4 additions & 2 deletions sdk/src/beta9/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ def warn(text: str) -> None:
_console.print(Text(text, style="bold yellow"))


def error(text: str) -> None:
def error(text: str, exit: bool = True) -> None:
_console.print(Text(text, style="bold red"))
sys.exit(1)

if exit:
sys.exit(1)


def url(text: str) -> None:
Expand Down
1 change: 0 additions & 1 deletion sdk/tests/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def test_func():
func.parent.function_stub.function_invoke.return_value = AsyncIterator(
[FunctionInvokeResponse(done=False, exit_code=1, result=b"")]
)
self.assertRaises(SystemExit, func)

def test_map(self):
# @Function(cpu=1, memory=128, image=Image(python_version="python3.8"))
Expand Down

0 comments on commit d52202e

Please sign in to comment.