Skip to content
This repository was archived by the owner on Feb 4, 2021. It is now read-only.

Commit a1e260c

Browse files
committed
Add debug log
1 parent bc79178 commit a1e260c

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

app/job/feed_job.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/ProgrammingLab/prolab-accounts/app/di"
1010
)
1111

12-
func feedJob(ctx context.Context, store di.StoreComponent) error {
12+
func feedJob(ctx context.Context, store di.StoreComponent, debug bool) error {
1313
bs := store.UserBlogStore(ctx)
1414
blogs, err := bs.ListUserBlogs()
1515
if err != nil {
@@ -32,7 +32,9 @@ func feedJob(ctx context.Context, store di.StoreComponent) error {
3232
if err != nil {
3333
return err
3434
}
35-
grpclog.Infof("feed job: created %v entries", n)
35+
if debug {
36+
grpclog.Infof("feed job: created %v entries", n)
37+
}
3638

3739
<-time.After(100 * time.Millisecond)
3840
}

app/job/job.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var (
2020
)
2121

2222
// Job represents job for worker
23-
type Job func(ctx context.Context, store di.StoreComponent) error
23+
type Job func(ctx context.Context, store di.StoreComponent, debug bool) error
2424

2525
// Start starts the worker
2626
func Start(store di.StoreComponent, cfg *config.Config) {
@@ -30,7 +30,7 @@ func Start(store di.StoreComponent, cfg *config.Config) {
3030
started = true
3131

3232
go func() {
33-
run(store, time.Duration(cfg.JobIntervalSec)*time.Second)
33+
run(store, cfg)
3434
}()
3535
}
3636

@@ -40,12 +40,14 @@ func Close() {
4040
stop <- struct{}{}
4141
}
4242

43-
func run(store di.StoreComponent, interval time.Duration) {
43+
func run(store di.StoreComponent, cfg *config.Config) {
44+
interval := time.Duration(cfg.JobIntervalSec) * time.Second
45+
4446
defer func() {
4547
if err := util.ErrorFromRecover(recover()); err != nil {
4648
grpclog.Errorf("job panic: %+v", err)
4749
grpclog.Infoln("worker is restarting...")
48-
run(store, interval)
50+
run(store, cfg)
4951
}
5052
}()
5153

@@ -55,7 +57,7 @@ func run(store di.StoreComponent, interval time.Duration) {
5557
select {
5658
case <-time.After(interval):
5759
for _, j := range jobs {
58-
err := j(context.Background(), store)
60+
err := j(context.Background(), store, cfg.DebugLog)
5961
if err != nil {
6062
grpclog.Errorf("job error: %+v", err)
6163
}

0 commit comments

Comments
 (0)