Skip to content

Auto reload the controller dev server - #47

Merged
knuton merged 2 commits into
dividat:developfrom
guyonvarch:auto-reload-controller-dev-server
Oct 28, 2020
Merged

knuton merged 2 commits into
dividat:developfrom
guyonvarch:auto-reload-controller-dev-server

Conversation

@guyonvarch

Copy link
Copy Markdown

Previously, we had to manually stop and restart the server after
each change.

Dune accepts the --watch parameter, But it does not work with
--exec, see ocaml/dune#2934.

There is a workaround, using an alias, see ocaml/dune#2934 (comment).

dune build --watch @install @run --profile release -j1 --no-buffer

server/dune

(alias
  (name run)
  (action (run ./run-server)))

run-server

cd ../../..

function finish {
  # Stop the running server
  lsof -i tcp:3333 | grep LISTEN | awk '{print $2}' | xargs kill
}

trap finish EXIT

finish
./_build/install/default/bin/playos-controller

But there are 2 problems:

  1. the server is started whenever the build succeeded or not. We could
    find a solution to inquire whether the build ran successfully or not in
    the run-server command.

  2. A long output is appended after the error message, requiring
    to scroll to see the error message. There may also be a solution to this
    problem.

It seems simpler to stick to our custom solution at this point.

Checklist

  • [ ] Changelog updated
  • [ ] Code documented

Previously, we had to manually stop and restart the server after
each change.

Dune accepts the `--watch` parameter, But it does not work with
`--exec`, see ocaml/dune#2934.

There is a workaround, using an alias, see ocaml/dune#2934 (comment).

`dune build --watch @install @run --profile release -j1 --no-buffer`

`server/dune`

```
(alias
  (name run)
  (action (run ./run-server)))
```

`run-server`

```bash
cd ../../..

function finish {
  # Stop the running server
  lsof -i tcp:3333 | grep LISTEN | awk '{print $2}' | xargs kill
}

trap finish EXIT

finish
./_build/install/default/bin/playos-controller
```

But there are 2 problems:

1. the server is started whenever the build succeeded or not. We could
find a solution to inquire whether the build ran successfully or not in
the `run-server` command.

2. A long output is appended after the error message, requiring
to scroll to see the error message. There may also be a solution to this
problem.

It seems simpler to stick to our custom solution at this point.
@guyonvarch guyonvarch added the reviewable Ready for initial or iterative review label Oct 26, 2020
@guyonvarch
guyonvarch requested a review from knuton October 26, 2020 09:07
Comment thread controller/bin/watch-command Outdated
if [ "$?" -eq 0 ]; then

# Kill already running server if any
lsof -i tcp:3333 | grep LISTEN | awk '{print $2}' | xargs kill 2>/dev/null

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the killing put behind this guard on purpose? It has the effect of letting the previously built server run if the new build fails, which I think could lead to confusion.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exact, fixed with 5c00e1e. I also improved the initial launch of bin/dev-server, after a dune clean.

@knuton knuton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well, with one caveat.

@knuton knuton added changes suggested Asking for changes before next round of reviewing and removed reviewable Ready for initial or iterative review labels Oct 27, 2020
@guyonvarch guyonvarch added reviewable Ready for initial or iterative review and removed changes suggested Asking for changes before next round of reviewing labels Oct 28, 2020
@knuton knuton removed the reviewable Ready for initial or iterative review label Oct 28, 2020
@knuton
knuton merged commit fdaf1af into dividat:develop Oct 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants