Skip to content

Commit

Permalink
Add Makefile and fix cmdline version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Jun 22, 2019
1 parent b42994d commit 9f1d073
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
LAST_COMMIT := $(shell git rev-parse --short HEAD)
LAST_COMMIT_DATE := $(shell git show -s --format=%ci ${LAST_COMMIT})
VERSION := $(shell git describe --abbrev=1)

BUILDSTR := ${VERSION} (build "\\\#"${LAST_COMMIT} $(shell date '+%Y-%m-%d %H:%M:%S'))

BIN := sql-jobber

.PHONY: build
build:
# Compile the main application.
go build -o ${BIN} -ldflags="-s -w -X 'main.buildString=${BUILDSTR}'"

.PHONY: test
test:
go test

.PHONY: clean
clean:
go clean
- rm -f ${BIN}
27 changes: 11 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ import (
const (
dbMySQL = "mysql"
dbPostgres = "postgres"

buildVersion = "unknown"
buildDate = "unknown"
)

type constants struct {
Expand Down Expand Up @@ -62,12 +59,10 @@ type DBConfig struct {
}

var (
sysLog = log.New(os.Stdout, "JOBBER: ", log.Ldate|log.Ltime|log.Lshortfile)

ko = koanf.New(".")

// Global Jobber container.
jobber = &Jobber{
buildString = "unknown"
sysLog = log.New(os.Stdout, "JOBBER: ", log.Ldate|log.Ltime|log.Lshortfile)
ko = koanf.New(".")
jobber = &Jobber{
Tasks: make(Tasks),
DBs: make(DBs),
ResultBackends: make(ResultBackends),
Expand All @@ -91,12 +86,18 @@ func init() {
f.String("worker-name", "sqljobber", "Name of this worker instance")
f.Int("worker-concurrency", 10, "Number of concurrent worker threads to run")
f.Bool("worker-only", false, "Don't start the HTTP server and run in worker-only mode?")
f.Bool("version", false, "Current version of the build")
f.Bool("version", false, "Current version and build")
f.Parse(os.Args[1:])

// Load commandline params.
ko.Load(posflag.Provider(f, ".", ko), nil)

// Display version.
if ko.Bool("version") {
fmt.Println(buildString)
os.Exit(0)
}

// Load the config file.
sysLog.Printf("reading config: %s", ko.String("config"))
if err := ko.Load(file.Provider(ko.String("config")), toml.Parser()); err != nil {
Expand All @@ -108,12 +109,6 @@ func init() {
}

func main() {
// Display version.
if ko.Bool("version") {
sysLog.Printf("commit: %v\nBuild: %v", buildVersion, buildDate)
return
}

mode := "default"
if ko.Bool("worker-only") {
mode = "worker only"
Expand Down

0 comments on commit 9f1d073

Please sign in to comment.