diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cd3150e..41109cb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0196d8f..a6fa6b6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,6 +6,7 @@ jobs: matrix: go: - 1.15 + - 1.16 name: Build runs-on: ubuntu-latest steps: diff --git a/.goreleaser.yml b/.goreleaser.yml index 885e3cb..36e0b91 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -9,6 +9,7 @@ builds: main: ./cmd/sqsjkr/main.go goarch: - amd64 + - arm64 goos: - darwin - linux diff --git a/go.mod b/go.mod index c1c6d38..d5b00e1 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index e55ec58..c1e3bfa 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/job.go b/job.go index a38e2d2..0451157 100644 --- a/job.go +++ b/job.go @@ -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 @@ -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 } diff --git a/sqsjkr_test.go b/sqsjkr_test.go index c22b848..d1c0fbd 100644 --- a/sqsjkr_test.go +++ b/sqsjkr_test.go @@ -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) diff --git a/worker.go b/worker.go index 01ddc9a..76a07f8 100644 --- a/worker.go +++ b/worker.go @@ -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() } @@ -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 } @@ -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 {