Skip to content

Commit

Permalink
cli: Add flag to specify progress interval
Browse files Browse the repository at this point in the history
  • Loading branch information
Acconut committed Aug 15, 2022
1 parent 870c434 commit 920deb3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cmd/tusd/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var Flags struct {
GrpcHooksRetry int
GrpcHooksBackoff int
EnabledHooks []hooks.HookType
ProgressHooksInterval int64
ShowVersion bool
ExposeMetrics bool
MetricsPath string
Expand Down Expand Up @@ -89,6 +90,7 @@ func ParseFlags() {
flag.StringVar(&Flags.AzObjectPrefix, "azure-object-prefix", "", "Prefix for Azure object names")
flag.StringVar(&Flags.AzEndpoint, "azure-endpoint", "", "Custom Endpoint to use for Azure BlockBlob Storage (requires azure-storage to be pass)")
flag.StringVar(&Flags.EnabledHooksString, "hooks-enabled-events", "pre-create,post-create,post-receive,post-terminate,post-finish", "Comma separated list of enabled hook events (e.g. post-create,post-finish). Leave empty to enable default events")
flag.Int64Var(&Flags.ProgressHooksInterval, "progress-hooks-interval", 1000, "Interval in milliseconds at which the post-receive progress hooks are emitted for each active upload")
flag.StringVar(&Flags.PluginHookPath, "hooks-plugin", "", "Path to a Go plugin for loading hook functions")
flag.StringVar(&Flags.FileHooksDir, "hooks-dir", "", "Directory to search for available hooks scripts")
flag.StringVar(&Flags.HttpHooksEndpoint, "hooks-http", "", "An HTTP endpoint to which hook events will be sent to")
Expand Down
1 change: 1 addition & 0 deletions cmd/tusd/cli/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func Serve() {
NotifyTerminatedUploads: true,
NotifyUploadProgress: true,
NotifyCreatedUploads: true,
UploadProgressInterval: time.Duration(Flags.ProgressHooksInterval) * time.Millisecond,
}

if err := SetupPreHooks(&config); err != nil {
Expand Down
9 changes: 9 additions & 0 deletions pkg/handler/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"net/url"
"os"
"time"
)

// Config provides a way to configure the Handler depending on your needs.
Expand Down Expand Up @@ -40,6 +41,10 @@ type Config struct {
// NotifyCreatedUploads indicates whether sending notifications about
// the upload having been created using the CreatedUploads channel should be enabled.
NotifyCreatedUploads bool
// UploadProgressInterval specifies the interval at which the upload progress
// notifications are sent to the UploadProgress channel, if enabled.
// Defaults to 1s.
UploadProgressInterval time.Duration
// Logger is the logger to use internally, mostly for printing requests.
Logger *log.Logger
// Respect the X-Forwarded-Host, X-Forwarded-Proto and Forwarded headers
Expand Down Expand Up @@ -92,5 +97,9 @@ func (config *Config) validate() error {
return errors.New("tusd: StoreComposer in Config needs to contain a non-nil core")
}

if config.UploadProgressInterval <= 0 {
config.UploadProgressInterval = 1 * time.Second
}

return nil
}
4 changes: 2 additions & 2 deletions pkg/handler/unrouted_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ var mimeInlineBrowserWhitelist = map[string]struct{}{
"audio/webm": struct{}{},
"video/webm": struct{}{},
"audio/ogg": struct{}{},
"video/ogg": struct{}{},
"video/ogg": struct{}{},
"application/ogg": struct{}{},
}

Expand Down Expand Up @@ -984,7 +984,7 @@ func (handler *UnroutedHandler) sendProgressMessages(hook HookEvent, reader *bod
previousOffset = hook.Upload.Offset
}
return
case <-time.After(1 * time.Second):
case <-time.After(handler.config.UploadProgressInterval):
hook.Upload.Offset = originalOffset + reader.bytesRead()
if hook.Upload.Offset != previousOffset {
handler.UploadProgress <- hook
Expand Down

0 comments on commit 920deb3

Please sign in to comment.