Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DUX-1499] Support running an application #143

Closed
9999years opened this issue Oct 24, 2023 · 6 comments
Closed

[DUX-1499] Support running an application #143

9999years opened this issue Oct 24, 2023 · 6 comments
Labels
linear Created by Linear-GitHub Sync Medium priority Created by Linear-GitHub Sync

Comments

@9999years
Copy link
Member

It's nice to run an application like a web server instead of running tests. This may require some additional hooks.

From SyncLinear.com | DUX-1499

@github-actions github-actions bot added the linear Created by Linear-GitHub Sync label Oct 24, 2023
@9999years 9999years added the Medium priority Created by Linear-GitHub Sync label Feb 26, 2024
@9999years 9999years added this to the 1.0 milestone Mar 1, 2024
@9999years 9999years removed this from the 1.0 milestone May 2, 2024
@running-grass
Copy link

@9999years

Thank you for implementing this feature. Now that the issue has been marked as completed, could you provide some guidance on how to use ghciwatch to run a server application? Specifically:

  1. Are there any new configuration options or commands to enable server mode?
  2. Is there documentation available on how to set up ghciwatch for running and auto-reloading a web server or similar application?
  3. Are there any best practices or examples you can share for using this new functionality?

Any information on how to effectively utilize this new feature would be greatly appreciated by the community.

@9999years
Copy link
Member Author

Filed a documentation ticket at #315, see #315 (comment) for an initial response (though there's still work to be done for this feature).

@LightAndLight
Copy link

This doesn't seem to work (tested on cfd9de8)

When --test-ghci is given a non-terminating IO action, the action isn't killed in response to reload/restart events. If I do something that would cause a reload/restart, then kill ghciwatch (e.g. with Ctrl+C), I see that the event was pending the termination of the --test-ghci action.

Example:

$ ghciwatch --command "cabal repl hedge-example" --watch hedge.cabal --restart-glob 'hedge.cabal' --watch src --restart-glob 'src/**/*.hs' --watch example --reload-glob 'example/Main.hs' --test-ghci main
Build profile: -w ghc-9.6.6 -O1
In order, the following will be built (use -v for more details):
 - hedge-0.1.0.0 (interactive) (exe:hedge-example) (first run)
Preprocessing executable 'hedge-example' for hedge-0.1.0.0...
GHCi, version 9.6.6: https://www.haskell.org/ghc/  :? for help

[1 of 2] Compiling Main             ( example/Main.hs, interpreted )
Ok, one module loaded.
• All good! Finished starting up in 738.02ms
• Running test command command=main
Server running on port 3000
^C
• Reloading ghci:
  • example/Main.hs

Error:   × Tasks failed:
  │ • run_ghci: channel closed

If I change main to something that terminates, then the above command works and correctly responds to changes.

@LightAndLight
Copy link

Right, GhciStdin::run_command is synchronous:

ghciwatch/src/ghci/mod.rs

Lines 921 to 923 in cfd9de8

self.stdin
.run_command(&mut self.stdout, command, log)
.await?;

which calls

/// Write a line on `stdin` and wait for a prompt on stdout.
///
/// The `line` should contain the trailing newline.
///
/// The `find` parameter determines where the prompt can be found in the output line.
#[instrument(skip(self, stdout), level = "debug")]
async fn write_line_with_prompt_at(
&mut self,
stdout: &mut GhciStdout,
line: &str,
find: FindAt,
log: &mut CompilationLog,
) -> miette::Result<()> {
self.stdin
.write_all(line.as_bytes())
.await
.into_diagnostic()?;
stdout.prompt(find, log).await
}

@9999years
Copy link
Member Author

@LightAndLight Would you open a new ticket for non-terminating applications? I'd really like to hear a proposed design, too, since I'm not sure how I'd implement that. (Maybe use something to save a binding corresponding to the async action...? But I think that various commands ghciwatch runs will clear bindings...)

@LightAndLight
Copy link

#325

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear Created by Linear-GitHub Sync Medium priority Created by Linear-GitHub Sync
Projects
None yet
Development

No branches or pull requests

3 participants