Skip to content

Conversation

@doanac
Copy link
Member

@doanac doanac commented Oct 23, 2025

These changes make it easier to use on-change handlers. Then end result is something like:

$ ./bin/fioup config-check
Extracting file: file=fioup-test
Extracting file: file=foo
Extracting file: file=fioconfig-oneshot-diag
Extracting file: file=foo
Extracting file: file=fioconfig-oneshot-diag
Extracting file: file=fioup-test
Running on-change command: file=fioup-test, args=[/tmp/andy.sh param2]
| ANDY called with param2
| 1
| 2
| exiting

Signed-off-by: Andy Doan <andy@foundries.io>
@doanac doanac requested review from detsch and vkhoroz October 23, 2025 16:41
internal/exec.go Outdated
Comment on lines 32 to 36
for range 2 {
if err := <-done; err != nil {
slog.Error("Error reading command output", "error", err)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

IMHO it'd be more clear what's going on if you replace a channel with sync.WaitGroup.
IIUC prefixAndCopy can log its error itself; removing any benefit from using a channel.

Copy link
Member Author

Choose a reason for hiding this comment

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

good call. I started to do that but originally thought I'd handle the error differently. This will simplify

Copy link
Member Author

Choose a reason for hiding this comment

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

updated in force push

cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {

if err := ExecIndented(cmd, "| "); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Interesting idea. Nice work.

Prefix all the change handler output with "| " so that our logs are
easier to follow

Signed-off-by: Andy Doan <andy@foundries.io>
@doanac doanac force-pushed the handler-improvments branch from 139eda7 to 901521a Compare October 23, 2025 17:15
@doanac doanac merged commit 152bd75 into foundriesio:main Oct 23, 2025
2 checks passed
@doanac doanac deleted the handler-improvments branch October 23, 2025 20:10
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