Skip to content

Commit

Permalink
Merge pull request #42 from kyleishie/sync_config_duration_fix
Browse files Browse the repository at this point in the history
Change Sync Config Duration Type
  • Loading branch information
kyleishie authored Feb 23, 2024
2 parents 9e175d7 + bd1fc71 commit 0556e43
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
6 changes: 5 additions & 1 deletion charts/beskar-ostree/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,8 @@ configData:
gcs:
bucket: beskar-ostree
azure:
container: beskar-ostree
container: beskar-ostree

sync:
timeout: 3600s # 1 hour
max_worker_count: 10
22 changes: 15 additions & 7 deletions internal/pkg/config/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,35 @@

package config

import "time"
import (
"time"

"google.golang.org/protobuf/types/known/durationpb"
)

const (
DefaultSyncTimeout = time.Hour
DefaultSyncMaxWorkerCount = 10
)

type SyncConfig struct {
Timeout time.Duration `yaml:"timeout"`
MaxWorkerCount int `yaml:"max_worker_count"`
Timeout *durationpb.Duration `yaml:"timeout"`
MaxWorkerCount int `yaml:"max_worker_count"`
}

func (sc SyncConfig) GetTimeout() time.Duration {
if sc.Timeout <= 0 {
func (sc *SyncConfig) GetTimeout() time.Duration {
if sc.Timeout == nil {
return DefaultSyncTimeout
}

if !sc.Timeout.IsValid() || sc.Timeout.GetSeconds() <= 0 {
return DefaultSyncTimeout
}

return sc.Timeout
return sc.Timeout.AsDuration()
}

func (sc SyncConfig) GetMaxWorkerCount() int {
func (sc *SyncConfig) GetMaxWorkerCount() int {
if sc.MaxWorkerCount <= 0 {
return DefaultSyncMaxWorkerCount
}
Expand Down
4 changes: 2 additions & 2 deletions internal/plugins/ostree/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func (p *Plugin) SyncRepository(ctx context.Context, repository string, properti
return err
}

if properties.Timeout <= 0 {
properties.Timeout = p.beskarOSTreeConfig.Sync.GetTimeout()
if properties.Timeout == nil || !properties.Timeout.IsValid() || properties.Timeout.GetSeconds() <= 0 {
properties.Timeout = p.beskarOSTreeConfig.Sync.Timeout
}

return p.repositoryManager.Get(ctx, repository).SyncRepository(ctx, properties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ gossip:
- 127.0.0.1:5102

sync:
timeout: 3600 # 1 hour
timeout: 3600s # 1 hour
max_worker_count: 10
2 changes: 1 addition & 1 deletion internal/plugins/ostree/pkg/ostreerepository/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (h *Handler) SyncRepository(_ context.Context, properties *apiv1.OSTreeRepo
h.clearState()
}()

ctx, cancel := context.WithTimeout(context.Background(), properties.Timeout)
ctx, cancel := context.WithTimeout(context.Background(), properties.Timeout.AsDuration())
defer cancel()

err = h.BeginLocalRepoTransaction(ctx, func(ctx context.Context, repo *libostree.Repo) (commit bool, transactionFnErr error) {
Expand Down
7 changes: 4 additions & 3 deletions pkg/plugins/ostree/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ package apiv1
import (
"context"
"regexp"
"time"

"google.golang.org/protobuf/types/known/durationpb"
)

const (
Expand Down Expand Up @@ -64,8 +65,8 @@ type OSTreeRepositorySyncRequest struct {
// Depth - The depth of the mirror. Defaults is 0, -1 means infinite.
Depth int `json:"depth"`

// Timeout - The timeout for the sync in seconds. Default is 20 minutes.
Timeout time.Duration `json:"timeout"`
// Timeout - The timeout for the sync in seconds. Default is 1 hour.
Timeout *durationpb.Duration `json:"timeout"`
}

// Mirror sync status.
Expand Down

0 comments on commit 0556e43

Please sign in to comment.