Skip to content

Commit

Permalink
cli: Allow configuration of file locker poll intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
Acconut committed Sep 6, 2023
1 parent 6b2bca8 commit 3d19094
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 62 deletions.
2 changes: 2 additions & 0 deletions cmd/tusd/cli/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ func CreateComposer() {
store.UseIn(Composer)

locker := filelocker.New(dir)
locker.AcquirerPollInterval = Flags.FilelockAcquirerPollInterval
locker.HolderPollInterval = Flags.FilelockHolderPollInterval
locker.UseIn(Composer)
}

Expand Down
124 changes: 64 additions & 60 deletions cmd/tusd/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,66 +11,68 @@ import (
)

var Flags struct {
HttpHost string
HttpPort string
HttpSock string
MaxSize int64
UploadDir string
Basepath string
ShowGreeting bool
DisableDownload bool
DisableTermination bool
DisableCors bool
CorsAllowOrigin string
CorsAllowCredentials bool
CorsAllowMethods string
CorsAllowHeaders string
CorsMaxAge string
CorsExposeHeaders string
ReadTimeout time.Duration
S3Bucket string
S3ObjectPrefix string
S3Endpoint string
S3PartSize int64
S3MaxBufferedParts int64
S3DisableContentHashes bool
S3DisableSSL bool
S3ConcurrentPartUploads int
GCSBucket string
GCSObjectPrefix string
AzStorage string
AzContainerAccessType string
AzBlobAccessTier string
AzObjectPrefix string
AzEndpoint string
EnabledHooksString string
PluginHookPath string
FileHooksDir string
HttpHooksEndpoint string
HttpHooksForwardHeaders string
HttpHooksRetry int
HttpHooksBackoff time.Duration
GrpcHooksEndpoint string
GrpcHooksRetry int
GrpcHooksBackoff time.Duration
EnabledHooks []hooks.HookType
ProgressHooksInterval time.Duration
ShowVersion bool
ExposeMetrics bool
MetricsPath string
ExposePprof bool
PprofPath string
PprofBlockProfileRate int
PprofMutexProfileRate int
BehindProxy bool
VerboseOutput bool
S3TransferAcceleration bool
TLSCertFile string
TLSKeyFile string
TLSMode string
ShutdownTimeout time.Duration
AcquireLockTimeout time.Duration
ExperimentalProtocol bool
HttpHost string
HttpPort string
HttpSock string
MaxSize int64
UploadDir string
Basepath string
ShowGreeting bool
DisableDownload bool
DisableTermination bool
DisableCors bool
CorsAllowOrigin string
CorsAllowCredentials bool
CorsAllowMethods string
CorsAllowHeaders string
CorsMaxAge string
CorsExposeHeaders string
ReadTimeout time.Duration
S3Bucket string
S3ObjectPrefix string
S3Endpoint string
S3PartSize int64
S3MaxBufferedParts int64
S3DisableContentHashes bool
S3DisableSSL bool
S3ConcurrentPartUploads int
GCSBucket string
GCSObjectPrefix string
AzStorage string
AzContainerAccessType string
AzBlobAccessTier string
AzObjectPrefix string
AzEndpoint string
EnabledHooksString string
PluginHookPath string
FileHooksDir string
HttpHooksEndpoint string
HttpHooksForwardHeaders string
HttpHooksRetry int
HttpHooksBackoff time.Duration
GrpcHooksEndpoint string
GrpcHooksRetry int
GrpcHooksBackoff time.Duration
EnabledHooks []hooks.HookType
ProgressHooksInterval time.Duration
ShowVersion bool
ExposeMetrics bool
MetricsPath string
ExposePprof bool
PprofPath string
PprofBlockProfileRate int
PprofMutexProfileRate int
BehindProxy bool
VerboseOutput bool
S3TransferAcceleration bool
TLSCertFile string
TLSKeyFile string
TLSMode string
ShutdownTimeout time.Duration
AcquireLockTimeout time.Duration
FilelockHolderPollInterval time.Duration
FilelockAcquirerPollInterval time.Duration
ExperimentalProtocol bool
}

func ParseFlags() {
Expand Down Expand Up @@ -105,6 +107,8 @@ func ParseFlags() {

// Filestore options
flag.StringVar(&Flags.UploadDir, "upload-dir", "./data", "Directory to store uploads in")
flag.DurationVar(&Flags.FilelockHolderPollInterval, "filelock-holder-poll-interval", 5*time.Second, "The holder of a lock polls regularly to see if another request handler needs the lock. This flag specifies the poll interval.")
flag.DurationVar(&Flags.FilelockAcquirerPollInterval, "filelock-acquirer-poll-interval", 2*time.Second, "The acquirer of a lock polls regularly to see if the lock has been released. This flag specifies the poll interval.")

// S3 options
flag.StringVar(&Flags.S3Bucket, "s3-bucket", "", "Use AWS S3 with this bucket as storage backend (requires the AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_REGION environment variables to be set)")
Expand Down
3 changes: 1 addition & 2 deletions pkg/filelocker/filelocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ type FileLocker struct {
// whether the path exists, use os.MkdirAll to ensure.
// In addition, a locking mechanism is provided.
func New(path string) FileLocker {
// TODO: Make configurable and check defaults
return FileLocker{path, time.Second, 3 * time.Second}
return FileLocker{path, 5 * time.Second, 2 * time.Second}
}

// UseIn adds this locker to the passed composer.
Expand Down

0 comments on commit 3d19094

Please sign in to comment.