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

script: Add support for interrupts #19

Merged
merged 2 commits into from
Oct 11, 2024
Merged

Conversation

joamaki
Copy link
Contributor

@joamaki joamaki commented Oct 10, 2024

This adds the ability to interrupt long-running commands. This is needed to implement something like "db watch table" that watches a table for changes until interrupted with ctrl-c.

See commits for more details.

You can try this out with:

go run ./example repl
> hive start
> events

@joamaki joamaki requested a review from a team as a code owner October 10, 2024 13:07
@joamaki joamaki requested review from ovidiutirla and removed request for a team October 10, 2024 13:07
script/makeraw_unix.go Outdated Show resolved Hide resolved
@joamaki joamaki force-pushed the pr/joamaki/script-interrupt branch 2 times, most recently from b87deb3 to 4d9910d Compare October 11, 2024 09:02
Copy link
Member

@pippolo84 pippolo84 left a comment

Choose a reason for hiding this comment

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

LGTM

script/makeraw_unix.go Show resolved Hide resolved
In order to implement e.g. "watch" command for StateDB we need
to be able to interrupt the command. To do this, we need to be able
to catch SIGINT, which requires the ISIG lflag and for that we'll
need our own "MakeRaw" function.

Additionally to be able to dump the log buffer periodically we
add a FlushLog() method.

Signed-off-by: Jussi Maki <[email protected]>
To try & show-case the interrupt support in script, change the
events command to show events until interrupted.

Example run:

  example % go run . repl
  example> hive start
  ...
  example> events
  {Reserve of peanut butter sandwiches: 99%}
  {Elevator music volume now set to 80%}
  {Mission completion:  5%}
  ^C (interrupted)
  example> hive stop

Signed-off-by: Jussi Maki <[email protected]>
@joamaki joamaki merged commit 8df06c4 into main Oct 11, 2024
1 check passed
@joamaki joamaki deleted the pr/joamaki/script-interrupt branch October 11, 2024 09:39
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