Skip to content

Commit

Permalink
Merge pull request #39 from kayac/fix-log-messages
Browse files Browse the repository at this point in the history
Fix log messages
  • Loading branch information
fujiwara committed Mar 4, 2021
2 parents e4f2814 + e4712cf commit ca8cc2d
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.15
go-version: 1.16
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ jobs:
matrix:
go:
- 1.15
- 1.16
name: Build
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ builds:
main: ./cmd/sqsjkr/main.go
goarch:
- amd64
- arm64
goos:
- darwin
- linux
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ go 1.15
require (
github.com/aws/aws-sdk-go v1.37.11
github.com/kayac/go-config v0.5.1
golang.org/x/net v0.0.0-20201002202402-0a1ea396d57c // indirect
)
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down
8 changes: 8 additions & 0 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,17 @@ type DefaultJob struct {
trigger string
}

func (j *DefaultJob) String() string {
return fmt.Sprintf("%#v", j)
}

// Job is sqsjkr job struct
type Job interface {
Execute(lock.Locker) ([]byte, error)
JobID() string
EventID() string
Command() string
String() string
}

// MessageBody for decoding json
Expand Down Expand Up @@ -208,6 +213,9 @@ func NewJob(msg *sqs.Message, trigger string) (Job, error) {
if !body.DisableLifeTimeTrigger {
dj.trigger = trigger
}
if dj.eventID == "" {
dj.eventID = *msg.MessageId
}
return dj, nil
}

Expand Down
4 changes: 4 additions & 0 deletions sqsjkr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ type TestJob struct {
jobID string
}

func (tj TestJob) String() string {
return tj.jobID
}

func (tj TestJob) Execute(locker lock.Locker) ([]byte, error) {
if tj.jobID == "job-duplicated" {
time.Sleep(time.Millisecond * 200)
Expand Down
10 changes: 5 additions & 5 deletions worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func SpawnWorker(sjkr SQSJkr, wid int, js <-chan Job, s *Stats) {
jobs: js,
stats: s,
}
logger.Infof("[worker_id:%d]spawn worker.", wid)
logger.Infof("[worker_id:%d] spawn worker.", wid)

worker.ReceiveMessage()
}
Expand All @@ -44,12 +44,12 @@ func (w Worker) ReceiveMessage() {
}

if err := w.executeJob(job); err != nil {
logger.Errorf("[worker_id:%d] %s", w.id, err.Error())
logger.Errorf("[worker_id:%d] execute job failed %s", w.id, err.Error())
}

}

logger.Infof("terminate %d worker", w.id)
logger.Infof("[worker_id:%d] terminating", w.id)
return
}

Expand All @@ -67,11 +67,11 @@ func (w Worker) executeJob(job Job) error {
output, err := job.Execute(w.sjkr.Locker())
if err != nil && output == nil {
atomic.AddInt64(&w.stats.Invocations.Failed, 1)
logger.Errorf("[event:%s] failed to invoke command, reason: %s", job.EventID(), err.Error())
logger.Errorf("[event:%s] failed to invoke command, reason: %s, job: %s", job.EventID(), err.Error(), job.String())
return err
} else if err != nil {
atomic.AddInt64(&w.stats.Invocations.Errored, 1)
logger.Errorf("[event:%s] error when to invoke command, reason: %s", job.EventID(), err.Error())
logger.Errorf("[event:%s] errored to invoke command, reason: %s, job: %s", job.EventID(), err.Error(), job.String())
logger.Errorf(string(output))
return err
} else {
Expand Down

0 comments on commit ca8cc2d

Please sign in to comment.