Skip to content

Commit

Permalink
fix: improve logging in master and worker services
Browse files Browse the repository at this point in the history
- Added logging for error handling in the MasterService when setting a worker node offline, replacing the previous trace.PrintError with a more informative log message.
- Enhanced WorkerService subscription method with debug logs to indicate subscription attempts and status, improving traceability during connection processes.
  • Loading branch information
tikazyq committed Dec 29, 2024
1 parent 5480097 commit ef499a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/node/service/master_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"errors"
"github.com/apex/log"
"github.com/cenkalti/backoff/v4"
"github.com/crawlab-team/crawlab/core/constants"
"github.com/crawlab-team/crawlab/core/grpc/server"
Expand All @@ -17,7 +18,6 @@ import (
"github.com/crawlab-team/crawlab/core/task/scheduler"
"github.com/crawlab-team/crawlab/core/utils"
"github.com/crawlab-team/crawlab/grpc"
"github.com/crawlab-team/crawlab/trace"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
mongo2 "go.mongodb.org/mongo-driver/mongo"
Expand Down Expand Up @@ -244,7 +244,7 @@ func (svc *MasterService) setWorkerNodeOffline(node *models.Node) {
return service.NewModelService[models.Node]().ReplaceById(node.Id, *node)
}, backoff.WithMaxRetries(backoff.NewConstantBackOff(1*time.Second), 3))
if err != nil {
trace.PrintError(err)
log.Errorf("failed to set worker node[%s] offline: %v", node.Key, err)
}
svc.sendNotification(node)
}
Expand Down
3 changes: 3 additions & 0 deletions core/node/service/worker_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,21 @@ func (svc *WorkerService) subscribe() {

for {
if svc.stopped {
svc.Infof("subscription stopped. exiting...")
return
}

// Use backoff for connection attempts
operation := func() error {
svc.Debugf("attempting to subscribe to master")
stream, err := client.GetGrpcClient().NodeClient.Subscribe(context.Background(), &grpc.NodeServiceSubscribeRequest{
NodeKey: svc.cfgSvc.GetNodeKey(),
})
if err != nil {
svc.Errorf("failed to subscribe to master: %v", err)
return err
}
svc.Debugf("subscribed to master")

// Handle messages
for {
Expand Down

0 comments on commit ef499a0

Please sign in to comment.