Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
et-nik committed Nov 21, 2021
2 parents c949b7c + 66b0f1e commit c0b20b4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
8 changes: 8 additions & 0 deletions internal/app/di/internal/definitions/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package definitions

import (
"context"
"net/http"
"time"

"github.com/gameap/daemon/internal/app/components"
Expand All @@ -19,6 +20,13 @@ func CreateServicesResty(ctx context.Context, c Container) *resty.Client {
restyClient.RetryMaxWaitTime = 10 * time.Minute
restyClient.SetLogger(c.Logger(ctx))

restyClient.AddRetryCondition(
func(r *resty.Response, err error) bool {
return r.StatusCode() == http.StatusTooManyRequests ||
r.StatusCode() == http.StatusBadGateway
},
)

return restyClient
}

Expand Down
8 changes: 7 additions & 1 deletion internal/app/repositories/gdtask_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (

"github.com/gameap/daemon/internal/app/domain"
"github.com/gameap/daemon/internal/app/interfaces"
"github.com/gameap/daemon/internal/app/logger"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)

type GDTaskRepository struct {
Expand Down Expand Up @@ -72,7 +74,11 @@ func (repository *GDTaskRepository) FindByStatus(
}

if server == nil {
return nil, errInvalidServerID
logger.WithFields(ctx, log.Fields{
"gameServerID": items[i].Server,
"gdTaskID": items[i].ID,
}).Warn(ctx, "invalid task, game server not found")
continue
}

gdTask := domain.NewGDTask(
Expand Down
16 changes: 9 additions & 7 deletions internal/app/repositories/server_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ type serverStruct struct {
type serverSaveStruct struct {
Installed uint8 `json:"installed"`
ProcessActive uint8 `json:"process_active"`
LastProcessCheck string `json:"last_process_check"`
LastProcessCheck string `json:"last_process_check,omitempty"`
}

type apiServerRepo struct {
Expand Down Expand Up @@ -263,15 +263,17 @@ func (apiRepo *apiServerRepo) FindByID(ctx context.Context, id int) (*domain.Ser
}

func (apiRepo *apiServerRepo) Save(ctx context.Context, server *domain.Server) error {
status := uint8(0)
srv := serverSaveStruct{
Installed: uint8(server.InstallationStatus()),
ProcessActive: 0,
}

if server.IsActive() {
status = 1
srv.ProcessActive = 1
}

srv := serverSaveStruct{
Installed: uint8(server.InstallationStatus()),
ProcessActive: status,
LastProcessCheck: server.LastStatusCheck().Format("2006-01-02 15:04:05"),
if !server.LastStatusCheck().IsZero() {
srv.LastProcessCheck = server.LastStatusCheck().Format("2006-01-02 15:04:05")
}

marshalled, err := json.Marshal(srv)
Expand Down

0 comments on commit c0b20b4

Please sign in to comment.