Repository navigation
Watch for connector requests with a one-shot background watcher, not Monitor #902
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
Open
robzolkos
wants to merge
4
commits into
main
Choose a base branch
from
connect-one-shot-watcher
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
32d2a31
Watch for connector requests with a one-shot background watcher, not …
robzolkos 7667cbf
Drain a stopped connector's file, read lines from the watcher's outpu…
robzolkos b42a8df
Require a writable handled file, and have a compacted session check t…
robzolkos e1d4116
Stop the watcher when the connector output it watches can't be read
robzolkos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| #!/usr/bin/env bash | ||
| set -u | ||
|
|
||
| once=false | ||
| if [ "${1:-}" = --once ]; then | ||
| once=true | ||
| shift | ||
| fi | ||
| if [ $# -ne 2 ]; then | ||
| echo "usage: watch-requests.sh [--once] <connector-output-file> <handled-file>" >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| out=$1 | ||
| handled=$2 | ||
|
|
||
| if [ ! -f "$out" ]; then | ||
| echo "watch-requests: no connector output at $out" >&2 | ||
| exit 2 | ||
| fi | ||
| if ! { mkdir -p "$(dirname "$handled")" && touch "$handled" && [ -f "$handled" ] && [ -r "$handled" ] && [ -w "$handled" ]; }; then | ||
| echo "watch-requests: can't use the handled file $handled" >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| unhandled() { | ||
| local lines | ||
| if [ ! -r "$out" ]; then | ||
| echo "watch-requests: can't read the connector output at $out" >&2 | ||
| exit 2 | ||
| fi | ||
| lines=$(($(wc -l < "$out"))) | ||
| [ "$lines" -gt 0 ] || return 1 | ||
| head -n "$lines" "$out" | HANDLED=$handled awk ' | ||
| BEGIN { while ((getline id < ENVIRON["HANDLED"]) > 0) seen[id] = 1 } | ||
| /"type":"request"/ && match($0, /"event_id":[0-9]+/) { | ||
| id = substr($0, RSTART + 11, RLENGTH - 11) | ||
| if (!(id in seen)) { print; seen[id] = 1; found = 1 } | ||
| } | ||
| END { exit !found }' | ||
| } | ||
|
|
||
| if [ "$once" = true ]; then | ||
| unhandled | ||
| exit 0 | ||
| fi | ||
|
|
||
| until unhandled; do | ||
| sleep 2 | ||
| done | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 Agreed that it would be worth having, but it is outside the scope I was given for this PR, which is the skill text and the script it ships. The 13 scenarios (now 15, with the directory and read-only cases) ran as an ad hoc local suite, and three mutations each failed their own case. Whether to commit them as a BATS file under
e2e/is a call for a maintainer. I will add one here if asked. Leaving this open for that decision.