Skip to content

Commit

Permalink
Merge pull request #35 from timeglass/switching_to_snow
Browse files Browse the repository at this point in the history
switched to cross platform snow watcher
  • Loading branch information
advdv committed Jun 9, 2015
2 parents d70d0a9 + 3c70fd8 commit 1e71f59
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 1,235 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ The source code will now be in your workspace and binaries are found in `$GOPATH

- __Handling `git stash`:__ Git has the ability to stash work for a later commit prior to switching branches. Currently the timer unable to detect this; adding extra time to next commit. Input welcome [here](https://github.com/Timeglass/glass/issues/3)
- __OS Restarts:__ Whenever the OS shuts down the repository might still contain uncommited work and a running timer, currently the timer is not restarted when this happens. _Input on how to achieve this is welcome [here](https://github.com/Timeglass/glass/issues/8)_

- __Network Volumes:__ Projects that are kept on network volumes (e.g using NFS) are known to have flaky support for file monitoring, especially on Linux (using inotify). This means automatic unpausing of the timer when editing a file might be broken in such projects. *I'm looking for cases that experience such problem, or other information that might be of help over* [here](https://github.com/timeglass/glass/issues/36)

## Contributors
in alphabetical order:
Expand Down
12 changes: 9 additions & 3 deletions command/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
"strings"
"time"

"github.com/timeglass/glass/_vendor/github.com/hashicorp/errwrap"
Expand Down Expand Up @@ -35,8 +36,13 @@ func NewClient(info *model.Daemon) *Client {
}
}

func (c *Client) getHostAddr() string {
//fixes windows lack of support for [::]
return strings.Replace(c.info.Addr, "[::]", "localhost", 1)
}

func (c *Client) Call(method string) error {
resp, err := c.Get(fmt.Sprintf("http://%s/%s", c.info.Addr, method))
resp, err := c.Get(fmt.Sprintf("http://%s/%s", c.getHostAddr(), method))
if err != nil {
return ErrDaemonDown
} else if resp.StatusCode != 200 {
Expand All @@ -47,7 +53,7 @@ func (c *Client) Call(method string) error {
}

func (c *Client) Lap() (time.Duration, error) {
resp, err := c.Get(fmt.Sprintf("http://%s/timer.lap", c.info.Addr))
resp, err := c.Get(fmt.Sprintf("http://%s/timer.lap", c.getHostAddr()))
if err != nil {
return 0, ErrDaemonDown
} else if resp.StatusCode != 200 {
Expand All @@ -74,7 +80,7 @@ func (c *Client) Lap() (time.Duration, error) {
}

func (c *Client) GetStatus() (*StatusData, error) {
resp, err := c.Get(fmt.Sprintf("http://%s/timer.status", c.info.Addr))
resp, err := c.Get(fmt.Sprintf("http://%s/timer.status", c.getHostAddr()))
if err != nil {
return nil, ErrDaemonDown
} else if resp.StatusCode != 200 {
Expand Down
4 changes: 3 additions & 1 deletion command/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ func (c *Start) Run(ctx *cli.Context) error {
return err
}

cmd := exec.Command("glass-daemon", fmt.Sprintf("--mbu=%s", conf.MBU))
//either the daemon broke/crashed or nothing is running at all, either way: use
//-force to make sure starting a new one succeeds
cmd := exec.Command("glass-daemon", "-force", fmt.Sprintf("--mbu=%s", conf.MBU))
err := cmd.Start()
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Failed to start Daemon: {{err}}"), err)
Expand Down
9 changes: 4 additions & 5 deletions glass-daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/timeglass/glass/_vendor/github.com/hashicorp/errwrap"

"github.com/timeglass/glass/model"
"github.com/timeglass/glass/watching"
"github.com/timeglass/snow/monitor"
)

var Version = "0.0.0"
Expand Down Expand Up @@ -41,20 +41,19 @@ func main() {
log.Fatal(errwrap.Wrapf("Failed to fetch current working dir: {{err}}", err))
}

monitor, err := watching.NewMonitor(dir)
monitor, err := monitor.New(dir, monitor.Recursive, time.Millisecond*50)
if err != nil {
log.Fatal(errwrap.Wrapf(fmt.Sprintf("Failed to create monitor for directory '%s': {{err}}"), err))
}

//whenever _something_ happends in any directory of the project delay timeout
timer.Wakeup = monitor.Events()
go func() {
for err := range monitor.Errors() {
log.Printf("Monitor Error: %s", err)
}
}()

err = monitor.Start()
//whenever _something_ happens in any directory, wakeup the timer
timer.Wakeup, err = monitor.Start()
if err != nil {
log.Fatal(errwrap.Wrapf(fmt.Sprintf("Failed to start monitor for directory '%s': {{err}}"), err))
}
Expand Down
6 changes: 3 additions & 3 deletions glass-daemon/timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"sync"
"time"

"github.com/timeglass/glass/watching"
"github.com/timeglass/snow/monitor"
)

type Timer struct {
Expand All @@ -16,7 +16,7 @@ type Timer struct {
inc chan chan time.Duration
reset chan struct{}

Wakeup <-chan watching.DirEvent
Wakeup <-chan monitor.DirEvent
*sync.Mutex
}

Expand All @@ -29,7 +29,7 @@ func NewTimer(mbu time.Duration, to time.Duration) *Timer {
inc: make(chan chan time.Duration),
reset: make(chan struct{}),

Wakeup: make(chan watching.DirEvent),
Wakeup: make(chan monitor.DirEvent),
Mutex: &sync.Mutex{},
}

Expand Down
13 changes: 6 additions & 7 deletions make.sh → make.bash
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#! /bin/sh
#! /bin/bash
GOOS=`go env GOOS`
GOARCH=`go env GOARCH`
XGOARCH=$GOARCH

function run_build_daemon {
go build -o $GOPATH/bin/glass-daemon -ldflags "-X main.Version `cat VERSION` -X main.Build `date -u +%Y%m%d%H%M%S`" ./glass-daemon
go build -o $GOPATH/bin/glass-daemon -ldflags "-X main.Version `cat VERSION` -X main.Build `date -u +%Y%m%d%H%M%S`" ./glass-daemon
}

function run_build_cli {
Expand All @@ -15,7 +16,6 @@ function run_run_daemon {
glass-daemon -bind :10000
}


function run_test {
echo "running all tests..."
go test ./...
Expand All @@ -30,7 +30,7 @@ function run_build {

function run_release_prepare_dirs {
echo "creating release directories..."
rm -fr bin/*
rm -fr bin/${GOOS}*
mkdir -p bin/${GOOS}_${GOARCH}
cp $GOPATH/bin/glass-daemon bin/${GOOS}_${GOARCH}
cp $GOPATH/bin/glass bin/${GOOS}_${GOARCH}
Expand All @@ -48,15 +48,14 @@ echo "Detected Arch '$GOARCH'"
case $1 in
"test") run_test ;;
"build" ) run_build ;;
"release" ) run_release ;;
"run-daemon" ) run_run_daemon ;;
"release" ) run_release ;;

#
# following commands are not portable
# and only work on osx with "github-release"
# "zip" and "shasum" installed and in PATH
#


# 1. zip all binaries
"publish-1" )
rm -fr bin/dist
Expand Down
20 changes: 12 additions & 8 deletions vcs/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,13 @@ func (g *Git) Hook() error {
hpath := filepath.Join(g.dir, "hooks")

//post checkout: start()
postchf, err := os.Create(filepath.Join(hpath, "post-checkout"))
postchpath := filepath.Join(hpath, "post-checkout")
postchf, err := os.Create(postchpath)
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Failed to create post-checkout '%s': {{err}}", postchf.Name()), err)
}

err = postchf.Chmod(0766)
err = os.Chmod(postchpath, 0766)
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Failed to make post-checkout file '%s' executable: {{err}}", hpath), err)
}
Expand All @@ -209,12 +210,13 @@ func (g *Git) Hook() error {
}

//prepare commit msg: status()
prepcof, err := os.Create(filepath.Join(hpath, "prepare-commit-msg"))
prepcopath := filepath.Join(hpath, "prepare-commit-msg")
prepcof, err := os.Create(prepcopath)
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Failed to create prepare-commit-msg '%s': {{err}}", postchf.Name()), err)
}

err = prepcof.Chmod(0766)
err = os.Chmod(prepcopath, 0766)
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Failed to make prepare-commit-msg file '%s' executable: {{err}}", hpath), err)
}
Expand All @@ -225,12 +227,13 @@ func (g *Git) Hook() error {
}

//post commit: lap()
postcof, err := os.Create(filepath.Join(hpath, "post-commit"))
postcopath := filepath.Join(hpath, "post-commit")
postcof, err := os.Create(postcopath)
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Failed to create post-commit '%s': {{err}}", postchf.Name()), err)
}

err = postcof.Chmod(0766)
err = os.Chmod(postcopath, 0766)
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Failed to make post-commit file '%s' executable: {{err}}", hpath), err)
}
Expand All @@ -241,12 +244,13 @@ func (g *Git) Hook() error {
}

//post receive: push()
prepushf, err := os.Create(filepath.Join(hpath, "pre-push"))
prepushpath := filepath.Join(hpath, "pre-push")
prepushf, err := os.Create(prepushpath)
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Failed to create pre-push '%s': {{err}}", postchf.Name()), err)
}

err = prepushf.Chmod(0766)
err = os.Chmod(prepushpath, 0766)
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Failed to make pre-push file '%s' executable: {{err}}", hpath), err)
}
Expand Down
161 changes: 0 additions & 161 deletions watching/monitor.go

This file was deleted.

0 comments on commit 1e71f59

Please sign in to comment.