Skip to content

Commit

Permalink
chore(deps): Updating cron usage
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Apr 18, 2021
1 parent 831b586 commit 41eab72
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 111 deletions.
2 changes: 1 addition & 1 deletion cmd/ketchup/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import (
"github.com/ViBiOh/httputils/v4/pkg/logger"
"github.com/ViBiOh/httputils/v4/pkg/owasp"
"github.com/ViBiOh/httputils/v4/pkg/prometheus"
"github.com/ViBiOh/httputils/v4/pkg/redis"
"github.com/ViBiOh/httputils/v4/pkg/renderer"
"github.com/ViBiOh/httputils/v4/pkg/server"
"github.com/ViBiOh/ketchup/pkg/github"
"github.com/ViBiOh/ketchup/pkg/helm"
"github.com/ViBiOh/ketchup/pkg/ketchup"
"github.com/ViBiOh/ketchup/pkg/middleware"
"github.com/ViBiOh/ketchup/pkg/notifier"
"github.com/ViBiOh/ketchup/pkg/redis"
"github.com/ViBiOh/ketchup/pkg/scheduler"
ketchupService "github.com/ViBiOh/ketchup/pkg/service/ketchup"
repositoryService "github.com/ViBiOh/ketchup/pkg/service/repository"
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/ViBiOh/auth/v2 v2.6.12
github.com/ViBiOh/httputils/v4 v4.6.0
github.com/ViBiOh/mailer v1.16.6
github.com/go-redis/redis/v8 v8.8.2
github.com/lib/pq v1.10.0
github.com/prometheus/client_golang v1.10.0
gopkg.in/yaml.v2 v2.4.0
Expand Down
3 changes: 1 addition & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgO
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-redis/redis/v8 v8.8.0 h1:fDZP58UN/1RD3DjtTXP/fFZ04TFohSYhjZDkcDe2dnw=
github.com/go-redis/redis/v8 v8.8.0/go.mod h1:F7resOH5Kdug49Otu24RjHWwgK7u9AmtqWMnCV1iP5Y=
github.com/go-redis/redis/v8 v8.8.2 h1:O/NcHqobw7SEptA0yA6up6spZVFtwE06SXM8rgLtsP8=
github.com/go-redis/redis/v8 v8.8.2/go.mod h1:F7resOH5Kdug49Otu24RjHWwgK7u9AmtqWMnCV1iP5Y=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
Expand Down
20 changes: 8 additions & 12 deletions pkg/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"github.com/ViBiOh/httputils/v4/pkg/flags"
"github.com/ViBiOh/httputils/v4/pkg/httpjson"
"github.com/ViBiOh/httputils/v4/pkg/logger"
"github.com/ViBiOh/httputils/v4/pkg/redis"
"github.com/ViBiOh/httputils/v4/pkg/request"
"github.com/ViBiOh/ketchup/pkg/model"
"github.com/ViBiOh/ketchup/pkg/redis"
"github.com/ViBiOh/ketchup/pkg/semver"
"github.com/prometheus/client_golang/prometheus"
)
Expand Down Expand Up @@ -88,18 +88,14 @@ func (a app) Start(registerer prometheus.Registerer, done <-chan struct{}) {

cron.New().Now().Each(time.Minute).OnError(func(err error) {
logger.Error("unable to get rate limit metrics: %s", err)
}).Start(func(_ time.Time) error {
_, err := a.redisApp.DoExclusive(context.Background(), "github_rate_limit_metrics", 45*time.Second, func(ctx context.Context) error {
value, err := a.getRateLimit(ctx)
if err != nil {
return err
}

metrics.Set(float64(value))
return nil
})
}).Exclusive(a.redisApp, "github_rate_limit_metrics", 45*time.Second).Start(func(ctx context.Context) error {
value, err := a.getRateLimit(ctx)
if err != nil {
return err
}

return err
metrics.Set(float64(value))
return nil
}, done)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/ketchup/ketchup.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"net/http"
"strings"

"github.com/ViBiOh/httputils/v4/pkg/redis"
"github.com/ViBiOh/httputils/v4/pkg/renderer"
"github.com/ViBiOh/ketchup/pkg/redis"
"github.com/ViBiOh/ketchup/pkg/service/ketchup"
"github.com/ViBiOh/ketchup/pkg/service/repository"
"github.com/ViBiOh/ketchup/pkg/service/user"
Expand Down
85 changes: 0 additions & 85 deletions pkg/redis/redis.go

This file was deleted.

14 changes: 5 additions & 9 deletions pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/ViBiOh/httputils/v4/pkg/cron"
"github.com/ViBiOh/httputils/v4/pkg/flags"
"github.com/ViBiOh/httputils/v4/pkg/logger"
"github.com/ViBiOh/httputils/v4/pkg/redis"
"github.com/ViBiOh/ketchup/pkg/notifier"
"github.com/ViBiOh/ketchup/pkg/redis"
)

// App of package
Expand Down Expand Up @@ -60,13 +60,9 @@ func New(config Config, notifierApp notifier.App, redisApp redis.App) App {
func (a app) Start(done <-chan struct{}) {
cron.New().At(a.hour).In(a.timezone).Days().OnError(func(err error) {
logger.Error("error while running ketchup notify: %s", err)
}).OnSignal(syscall.SIGUSR1).Start(func(_ time.Time) error {
_, err := a.redisApp.DoExclusive(context.Background(), "ketchup_notify", 10*time.Minute, func(ctx context.Context) error {
logger.Info("Starting ketchup notifier")
defer logger.Info("Ending ketchup notifier")
return a.notifierApp.Notify(ctx)
})

return err
}).OnSignal(syscall.SIGUSR1).Exclusive(a.redisApp, "ketchup_notify", 10*time.Minute).Start(func(ctx context.Context) error {
logger.Info("Starting ketchup notifier")
defer logger.Info("Ending ketchup notifier")
return a.notifierApp.Notify(ctx)
}, done)
}

0 comments on commit 41eab72

Please sign in to comment.