Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Speed up event processing #8

Merged
merged 12 commits into from
Apr 24, 2020
Prev Previous commit
Next Next commit
Create watch before initial sync
Resolves #7
  • Loading branch information
ammario committed Apr 24, 2020
commit a675d5ec3743ee612230a1d06018762b4270b9fb
18 changes: 10 additions & 8 deletions internal/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,17 @@ const (
// Use this command to debug what wasn't sync'd correctly:
// rsync -e "coder sh" -nicr ~/Projects/cdr/coder-cli/. ammar:/home/coder/coder-cli/
func (s Sync) Run() error {
events := make(chan notify.EventInfo, maxInflightInotify)
// Set up a recursive watch.
// We do this before the initial sync so we can capture any changes that may have happened during sync.
err := notify.Watch(path.Join(s.LocalDir, "..."), events, notify.All)
if err != nil {
return xerrors.Errorf("create watch: %w", err)
}
defer notify.Stop(events)

setConsoleTitle("⏳ syncing project")
err := s.initSync()
err = s.initSync()
if err != nil {
return err
}
Expand All @@ -232,13 +241,6 @@ func (s Sync) Run() error {
return nil
}

events := make(chan notify.EventInfo, maxInflightInotify)
// Set up a recursive watch.
err = notify.Watch(path.Join(s.LocalDir, "..."), events, notify.All)
if err != nil {
return xerrors.Errorf("create watch: %w", err)
}
defer notify.Stop(events)

flog.Info("watching %s for changes", s.LocalDir)

Expand Down