cli: Add flag to specify progress interval

This commit is contained in:
Marius 2022-08-15 23:26:58 +02:00
parent 870c434485
commit 920deb3df7
4 changed files with 14 additions and 2 deletions

View File

@ -46,6 +46,7 @@ var Flags struct {
GrpcHooksRetry int
GrpcHooksBackoff int
EnabledHooks []hooks.HookType
ProgressHooksInterval int64
ShowVersion bool
ExposeMetrics bool
MetricsPath string
@ -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")

View File

@ -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 {

View File

@ -5,6 +5,7 @@ import (
"log"
"net/url"
"os"
"time"
)
// Config provides a way to configure the Handler depending on your needs.
@ -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
@ -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
}

View File

@ -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{}{},
}
@ -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