Skip to content

Commit

Permalink
makefile, fix logger interface and travis
Browse files Browse the repository at this point in the history
  • Loading branch information
mcuadros committed Dec 19, 2016
1 parent e364792 commit a578833
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: go
sudo: false

go:
- 1.5
- 1.7.x

script:
- make test-coverage
Expand Down
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PACKAGES = github.com/mcuadros/ofelia/core \
BASE_PATH := $(shell pwd)
BUILD_PATH := $(BASE_PATH)/build
SHA1 := $(shell git log --format='%H' -n 1 | cut -c1-10)
BUILD := $(shell date)
BUILD := $(shell date +"%m-%d-%Y_%H_%M_%S")
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)

# Packages content
Expand All @@ -36,32 +36,32 @@ ifneq ($(origin TRAVIS_TAG), undefined)
endif

# Rules
all: clean upload
all: clean packages

dependencies:
$(GOGET) -t ./...
@$(GOGET) -t ./...; \
for i in $(DEPENDENCIES); do $(GOGET) $$i; done

test: dependencies
for p in $(PACKAGES); do \
@for p in $(PACKAGES); do \
$(GOTEST) $${p}; \
done;

test-coverage: dependencies
echo "mode: $(COVERAGE_MODE)" > $(COVERAGE_REPORT); \
@echo "mode: $(COVERAGE_MODE)" > $(COVERAGE_REPORT); \
for p in $(PACKAGES); do \
$(GOTEST) $${p} -coverprofile=tmp_$(COVERAGE_REPORT) -covermode=$(COVERAGE_MODE); \
cat tmp_$(COVERAGE_REPORT) | grep -v "mode: $(COVERAGE_MODE)" >> $(COVERAGE_REPORT); \
rm tmp_$(COVERAGE_REPORT); \
done;

packages: dependencies
for os in $(PKG_OS); do \
@for os in $(PKG_OS); do \
for arch in $(PKG_ARCH); do \
cd $(BASE_PATH); \
mkdir -p $(BUILD_PATH)/$(PROJECT)_$${os}_$${arch}; \
for cmd in $(COMMANDS); do \
GOOS=$${os} GOARCH=$${arch} $(GOCMD) build -ldflags "-X main.version $(BRANCH) -X main.build \"$(BUILD)\"" -o $(BUILD_PATH)/$(PROJECT)_$${os}_$${arch}/$${cmd} $${cmd}.go ; \
GOOS=$${os} GOARCH=$${arch} $(GOCMD) build -ldflags "-X main.version=$(BRANCH) -X main.build=$(BUILD)" -o $(BUILD_PATH)/$(PROJECT)_$${os}_$${arch}/$${cmd} $${cmd}.go;\
done; \
for content in $(PKG_CONTENT); do \
cp -rf $${content} $(BUILD_PATH)/$(PROJECT)_$${os}_$${arch}/; \
Expand All @@ -71,5 +71,5 @@ packages: dependencies
done;

clean:
rm -rf $(BUILD_PATH)
@rm -rf $(BUILD_PATH); \
$(GOCLEAN) .
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

It has been a long time since [`cron`](https://en.wikipedia.org/wiki/Cron) was released, actually more than 28 years. The world has changed a lot and especially since the `Docker` revolution. **Vixie's cron** works great but it's not extensible and it's hard to debug when something goes wrong.

Many solutions are available: ready to go containerized `crons`, wrappers for your commands, etc. but in the end simple tasks become complex.
Many solutions are available: ready to go containerized `crons`, wrappers for your commands, etc. but in the end simple tasks become complex.

### How?

Expand Down
4 changes: 2 additions & 2 deletions cli/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (c *DaemonCommand) setSignals() {

go func() {
sig := <-c.signals
c.scheduler.Logger.Warning(
c.scheduler.Logger.Warningf(
"Signal recieved: %s, shuting down the process\n", sig,
)

Expand All @@ -76,6 +76,6 @@ func (c *DaemonCommand) shutdown() error {
return nil
}

c.scheduler.Logger.Warning("Waiting running jobs.")
c.scheduler.Logger.Warningf("Waiting running jobs.")
return c.scheduler.Stop()
}
10 changes: 5 additions & 5 deletions core/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ func (c *middlewareContainer) Middlewares() []Middleware {
}

type Logger interface {
Critical(args ...interface{})
Debug(args ...interface{})
Error(args ...interface{})
Notice(args ...interface{})
Warning(args ...interface{})
Criticalf(format string, args ...interface{})
Debugf(format string, args ...interface{})
Errorf(format string, args ...interface{})
Noticef(format string, args ...interface{})
Warningf(format string, args ...interface{})
}

func randomID() string {
Expand Down
10 changes: 5 additions & 5 deletions core/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ func (j *TestJob) Run(ctx *Context) error {

type TestLogger struct{}

func (*TestLogger) Critical(format string, args ...interface{}) {}
func (*TestLogger) Debug(format string, args ...interface{}) {}
func (*TestLogger) Error(format string, args ...interface{}) {}
func (*TestLogger) Notice(format string, args ...interface{}) {}
func (*TestLogger) Warning(format string, args ...interface{}) {}
func (*TestLogger) Criticalf(format string, args ...interface{}) {}
func (*TestLogger) Debugf(format string, args ...interface{}) {}
func (*TestLogger) Errorf(format string, args ...interface{}) {}
func (*TestLogger) Noticef(format string, args ...interface{}) {}
func (*TestLogger) Warningf(format string, args ...interface{}) {}
12 changes: 6 additions & 6 deletions core/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewScheduler(l Logger) *Scheduler {
}

func (s *Scheduler) AddJob(j Job) error {
s.Logger.Notice("New job registered %q - %q - %q", j.GetName(), j.GetCommand(), j.GetSchedule())
s.Logger.Noticef("New job registered %q - %q - %q", j.GetName(), j.GetCommand(), j.GetSchedule())

if j.GetSchedule() == "" {
return ErrEmptySchedule
Expand All @@ -51,7 +51,7 @@ func (s *Scheduler) Start() error {
return ErrEmptyScheduler
}

s.Logger.Debug("Starting scheduler with %d jobs", len(s.Jobs))
s.Logger.Debugf("Starting scheduler with %d jobs", len(s.Jobs))

s.mergeMiddlewares()
s.isRunning = true
Expand Down Expand Up @@ -97,7 +97,7 @@ func (w *jobWrapper) Run() {
func (w *jobWrapper) start(ctx *Context) {
ctx.Start()

ctx.Logger.Debug(
ctx.Logger.Debugf(
"%s - Job started %q - %q",
ctx.Job.GetName(), ctx.Execution.ID, ctx.Job.GetCommand(),
)
Expand All @@ -117,10 +117,10 @@ func (w *jobWrapper) stop(ctx *Context, err error) {
)

if ctx.Execution.Failed {
ctx.Logger.Error(msg)
ctx.Logger.Errorf(msg)
} else if ctx.Execution.Skipped {
ctx.Logger.Warning(msg)
ctx.Logger.Warningf(msg)
} else {
ctx.Logger.Notice(msg)
ctx.Logger.Noticef(msg)
}
}
10 changes: 5 additions & 5 deletions middlewares/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func (j *TestJob) Run(ctx *core.Context) error {

type TestLogger struct{}

func (*TestLogger) Critical(format string, args ...interface{}) {}
func (*TestLogger) Debug(format string, args ...interface{}) {}
func (*TestLogger) Error(format string, args ...interface{}) {}
func (*TestLogger) Notice(format string, args ...interface{}) {}
func (*TestLogger) Warning(format string, args ...interface{}) {}
func (*TestLogger) Criticalf(format string, args ...interface{}) {}
func (*TestLogger) Debugf(format string, args ...interface{}) {}
func (*TestLogger) Errorf(format string, args ...interface{}) {}
func (*TestLogger) Noticef(format string, args ...interface{}) {}
func (*TestLogger) Warningf(format string, args ...interface{}) {}
2 changes: 1 addition & 1 deletion middlewares/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (m *Mail) Run(ctx *core.Context) error {
if ctx.Execution.Failed || !m.MailOnlyOnError {
err := m.sendMail(ctx)
if err != nil {
ctx.Logger.Error("Mail error: %q", err)
ctx.Logger.Errorf("Mail error: %q", err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion middlewares/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (m *Save) Run(ctx *core.Context) error {
if ctx.Execution.Failed || !m.SaveOnlyOnError {
err := m.saveToDisk(ctx)
if err != nil {
ctx.Logger.Error("Save error: %q", err)
ctx.Logger.Errorf("Save error: %q", err)
}
}

Expand Down
4 changes: 2 additions & 2 deletions middlewares/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ func (m *Slack) pushMessage(ctx *core.Context) {

r, err := http.PostForm(m.SlackWebhook, values)
if err != nil {
ctx.Logger.Error("Slack error calling %q error: %q", m.SlackWebhook, err)
ctx.Logger.Errorf("Slack error calling %q error: %q", m.SlackWebhook, err)
} else if r.StatusCode != 200 {
ctx.Logger.Error("Slack error non-200 status code calling %q", m.SlackWebhook)
ctx.Logger.Errorf("Slack error non-200 status code calling %q", m.SlackWebhook)
}
}

Expand Down

0 comments on commit a578833

Please sign in to comment.