Skip to content

Commit

Permalink
fix: minor adjustments of docs,imports
Browse files Browse the repository at this point in the history
  • Loading branch information
GGXXLL committed Jan 17, 2022
1 parent f2026e4 commit 160ea54
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 24 deletions.
6 changes: 3 additions & 3 deletions c.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package core
import (
"context"
"fmt"
"github.com/spf13/cobra"
"reflect"

"github.com/DoNewsCode/core/codec/yaml"
Expand All @@ -22,6 +21,7 @@ import (
"github.com/go-kit/log"
"github.com/knadh/koanf/providers/confmap"
"github.com/knadh/koanf/providers/file"
"github.com/spf13/cobra"
"go.uber.org/dig"
)

Expand Down Expand Up @@ -225,7 +225,7 @@ func (c *C) AddModule(modules ...interface{}) {
}
}

// Provide adds a dependencies provider to the core. Note the dependency provider
// Provide adds dependencies provider to the core. Note the dependency provider
// must be a function in the form of:
//
// func(foo Foo) Bar
Expand Down Expand Up @@ -385,7 +385,7 @@ func (c *C) Shutdown() {
}
}

// AddModuleFunc add the module after Invoking its' constructor. Clean up
// AddModuleFunc add the module after Invoking its constructor. Clean up
// functions and errors are handled automatically.
func (c *C) AddModuleFunc(constructor interface{}) {
c.provide(constructor)
Expand Down
12 changes: 6 additions & 6 deletions cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,20 @@ func (c *Cron) Run(ctx context.Context) error {
if c.jobDescriptors[0].next.After(now) || c.jobDescriptors[0].next.IsZero() {
break
}
descriptor := heap.Pop(&c.jobDescriptors)
descriptor := heap.Pop(&c.jobDescriptors).(*JobDescriptor)

descriptor.(*JobDescriptor).prev = descriptor.(*JobDescriptor).next
descriptor.(*JobDescriptor).next = descriptor.(*JobDescriptor).Schedule.Next(now)
descriptor.prev = descriptor.next
descriptor.next = descriptor.Schedule.Next(now)
heap.Push(&c.jobDescriptors, descriptor)

var innerCtx context.Context
innerCtx = context.WithValue(ctx, prevContextKey, descriptor.(*JobDescriptor).prev)
innerCtx = context.WithValue(innerCtx, nextContextKey, descriptor.(*JobDescriptor).next)
innerCtx = context.WithValue(ctx, prevContextKey, descriptor.prev)
innerCtx = context.WithValue(innerCtx, nextContextKey, descriptor.next)

c.quitWaiter.Add(1)
go func() {
defer c.quitWaiter.Done()
descriptor.(*JobDescriptor).Run(innerCtx)
descriptor.Run(innerCtx)
}()
}
c.lock.L.Unlock()
Expand Down
3 changes: 2 additions & 1 deletion cron/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package cron_test
import (
"context"
"fmt"
"time"

"github.com/DoNewsCode/core"
"github.com/DoNewsCode/core/cron"
"github.com/DoNewsCode/core/di"
"github.com/DoNewsCode/core/observability"
"time"
)

type CronModule struct {
Expand Down
5 changes: 3 additions & 2 deletions cron/metrics.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package cron

import (
"github.com/go-kit/kit/metrics"
"time"

"github.com/go-kit/kit/metrics"
)

// CronJobMetrics collects metrics for cron jobs.
type CronJobMetrics struct {
cronJobDurationSeconds metrics.Histogram
cronJobFailCount metrics.Counter

// labels that has been set
// labels that have been set
module string
job string
schedule string
Expand Down
2 changes: 1 addition & 1 deletion cron/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func WithTracing(tracer opentracing.Tracer) JobOption {
span.SetTag("schedule", descriptor.RawSpec)
err := innerRun(ctx)
if err != nil {
ext.Error.Set(span, true)
ext.LogError(span, err)
return err
}
return nil
Expand Down
7 changes: 4 additions & 3 deletions cron/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"bytes"
"context"
"errors"
"strings"
"testing"
"time"

"github.com/DoNewsCode/core/internal/stub"
"github.com/go-kit/log"
"github.com/opentracing/opentracing-go/mocktracer"
"github.com/robfig/cron/v3"
"strings"
"testing"
"time"
)

type mockScheduler func(now time.Time) time.Time // mockScheduler is a function that returns the next time to run
Expand Down
3 changes: 2 additions & 1 deletion internal/stub/metrics.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package stub

import (
"github.com/go-kit/kit/metrics"
"sync"

"github.com/go-kit/kit/metrics"
)

// LabelValues contains the set of labels and their corresponding values.
Expand Down
6 changes: 3 additions & 3 deletions observability/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ func ProvideGRPCRequestDurationSeconds(in MetricsIn) *srvgrpc.RequestDurationSec
return srvgrpc.NewRequestDurationSeconds(prometheus.NewHistogram(grpc))
}

// ProvideCronJobMetrics returns a *deprecated_cronopts.CronJobMetrics that is designed to
// ProvideCronJobMetrics returns a *cron.CronJobMetrics that is designed to
// measure cron job metrics. The returned metrics can be used like this:
// metrics := deprecated_cronopts.NewCronJobMetrics(...)
// metrics := cron.NewCronJobMetrics(...)
// job := cron.NewChain(
// cron.Recover(logger),
// deprecated_cronopts.Measure(metrics),
// cron.Measure(metrics),
// ).Then(job)
func ProvideCronJobMetrics(in MetricsIn) *cron.CronJobMetrics {
histogram := stdprometheus.NewHistogramVec(stdprometheus.HistogramOpts{
Expand Down
8 changes: 4 additions & 4 deletions serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import (
"bytes"
"context"
"errors"
"github.com/DoNewsCode/core/cron"
"github.com/DoNewsCode/core/di"
"github.com/DoNewsCode/core/observability"
deprecatedcron "github.com/robfig/cron/v3"
"os"
"runtime"
"sync/atomic"
"testing"
"time"

"github.com/DoNewsCode/core/cron"
"github.com/DoNewsCode/core/di"
"github.com/DoNewsCode/core/logging"
"github.com/DoNewsCode/core/observability"
"github.com/go-kit/log"
"github.com/oklog/run"
deprecatedcron "github.com/robfig/cron/v3"
"github.com/stretchr/testify/assert"
)

Expand Down

0 comments on commit 160ea54

Please sign in to comment.