Skip to content

Commit

Permalink
fix issue #85: prepare to handle SIGTERM
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Aug 10, 2017
1 parent f083c10 commit b44e2ca
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -68,7 +68,7 @@ research:

.PHONY: test-cmd
test-cmd:
docker run --rm \
docker run --rm -it \
-v '$(GOPATH)/src/$(GO_PACKAGE)':'/go/src/$(GO_PACKAGE)' \
-w '/go/src/$(GO_PACKAGE)' \
golang:1.7 \
Expand Down
36 changes: 35 additions & 1 deletion cmd/semaphore/main.go
@@ -1,13 +1,47 @@
package main

import (
"context"
"flag"
"fmt"
"os"
"os/signal"
"strings"
)

/*
Prototype:
$ semaphore create 4
$ semaphore add -- docker build ...
$ semaphore add -- docker build ...
...
$ semaphore wait | semaphore wait --notify
... show progress (colored output)
[==>........] 2/10
command `docker build ...`
output:
...
command...
*/
func main() {
ctx, cancel := context.WithCancel(context.Background())
c := make(chan os.Signal, 1)

signal.Notify(c, os.Interrupt)
defer func() {
signal.Stop(c)
cancel()
}()

select {
case <-c:
cancel()
case <-ctx.Done():
}

flag.Parse()
fmt.Println(strings.Join(flag.Args(), ", "))
fmt.Println(commit, date, version)
fmt.Println(commit, date, version, os.TempDir())
}

0 comments on commit b44e2ca

Please sign in to comment.