Skip to content

Commit

Permalink
[fix] 修复启动依赖项
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrie committed Jan 25, 2023
1 parent fe57be0 commit 8069449
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
12 changes: 12 additions & 0 deletions cmd/spider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ func lc(
},
})

lifecycle.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
return spiderUpdatePicture.Run(ctx)
},
OnStop: func(ctx context.Context) error {
if err := spiderUpdatePicture.Stop(ctx); err != nil {
return err
}
return shutdown.Shutdown()
},
})

lifecycle.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
go func() {
Expand Down
1 change: 1 addition & 0 deletions internal/app/spider/picture.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (p *Picture) spider() error {
var offset uint64 = 0
exist := false //判断有没有已经爬过
for hasMore == 1 && !exist {
time.Sleep(400 * time.Millisecond)
data, err := p.sdk.TopicDynamics(topicName, offset)
if err != nil {
p.logger.Error("TopicDynamics error", zap.String("topic_name", topicName), zap.String("offset", fmt.Sprintf("%d", offset)), zap.Error(err))
Expand Down
5 changes: 3 additions & 2 deletions internal/app/spider/update_dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type UpdateDynamic struct {
sdk *bilibili.SDK
}

func NewUpdateDynamic(db *gorm.DB, logger *zap.Logger, sdk *bilibili.SDK) *Update {
return &Update{
func NewUpdateDynamic(db *gorm.DB, logger *zap.Logger, sdk *bilibili.SDK) *UpdateDynamic {
return &UpdateDynamic{
stopChan: make(chan bool),
db: db,
logger: logger,
Expand Down Expand Up @@ -80,6 +80,7 @@ func (u *UpdateDynamic) spider() error {
return nil
}
for _, v := range list {
time.Sleep(200 * time.Millisecond)
dynamic, err := u.sdk.Dynamic(v.DynamicID)
if err != nil {
u.logger.Error("Dynamic error", zap.Int("dynamic_id", int(v.DynamicID)), zap.Error(err))
Expand Down
5 changes: 3 additions & 2 deletions internal/launcher/app.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package launcher

import (
"git.vtb.link/eoefans/internal/pkg/config"
"git.vtb.link/eoefans/internal/pkg/log"
"math/rand"
"time"

"git.vtb.link/eoefans/internal/pkg/config"
"git.vtb.link/eoefans/internal/pkg/log"

"go.uber.org/fx"
"go.uber.org/fx/fxevent"
"go.uber.org/zap"
Expand Down

0 comments on commit 8069449

Please sign in to comment.