Skip to content

Conversation

@chijiooke
Copy link

Adds a filewatcher CLI that watches a directory for PDF file changes and posts normalized file events to an HTTP API. Includes event debouncing for macOS, structured logging, and a clean, extensible architecture for future processing pipelines to examples directory for go lang

## Requirements

* Go **1.22+**
* macOS (uses `fsnotify`, compatible with FSEvents)
Copy link
Owner

Choose a reason for hiding this comment

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

I think fsnotify according to their readme is cross platform right? Or atleast can work on linux&mac

* PDF-only file filtering
* Detects file lifecycle events:

* `FILE_ADDED`
Copy link
Owner

Choose a reason for hiding this comment

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

Nice work outlining this

I'm curious how file renames are represented. As a FILE_UPDATED? or as a FILE_REMOVED+FILE_ADDED

Copy link
Owner

Choose a reason for hiding this comment

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

We can probably ignore the built binary as well

* Directory not found → Program exits with a descriptive error
* API failure → Logged; watcher continues running
* Permission issues → Logged as warnings
* Non-PDF files → Ignored
Copy link
Owner

Choose a reason for hiding this comment

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

More like it ignores files not suffixed with .pdf ... they may be valid pdf files but you took the suffix detection approach (which is fine for this example tbh)

Alternatively we could have used a detection approach where we try and check the first 5 bytes are %PDF- and that would potentially catch more valid pdfs. However, because we are leaving actual PDF parsing for some upstream component I'd say the suffix approach is fine but we should properly document

cfg := &Config{}

flag.StringVar(&cfg.Dir, "dir", "", "Directory to watch")
flag.StringVar(&cfg.APIURL, "api-url", "", "API endpoint")
Copy link
Owner

Choose a reason for hiding this comment

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

HTTP API is not a bad choice tbh but given that we expect the watcher to run on the same system as the future components (atleast for this example), how about a unix domain socket path?

Copy link
Owner

Choose a reason for hiding this comment

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

I think this is deprecated now given the structure below


---

## Project Structure
Copy link
Owner

Choose a reason for hiding this comment

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

The file watcher is one piece out of the project... perhaps the entire project should be named something like pdfsearch and the filewatcher is one binary under pdfsearch that pushes events to the indexer

Copy link
Owner

Choose a reason for hiding this comment

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

Either that or filewatcher, indexer and searcher are things you spin up at once as such

// instantiate some connecting channel between watcher and indexer
go fileWatcher.Watch(connChann)
go indexer.Index(connChann)
go searcher.InitAPI()

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