cli: Add flag to specify progress interval
This commit is contained in:
parent
870c434485
commit
920deb3df7
|
@ -46,6 +46,7 @@ var Flags struct {
|
||||||
GrpcHooksRetry int
|
GrpcHooksRetry int
|
||||||
GrpcHooksBackoff int
|
GrpcHooksBackoff int
|
||||||
EnabledHooks []hooks.HookType
|
EnabledHooks []hooks.HookType
|
||||||
|
ProgressHooksInterval int64
|
||||||
ShowVersion bool
|
ShowVersion bool
|
||||||
ExposeMetrics bool
|
ExposeMetrics bool
|
||||||
MetricsPath string
|
MetricsPath string
|
||||||
|
@ -89,6 +90,7 @@ func ParseFlags() {
|
||||||
flag.StringVar(&Flags.AzObjectPrefix, "azure-object-prefix", "", "Prefix for Azure object names")
|
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.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.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.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.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")
|
flag.StringVar(&Flags.HttpHooksEndpoint, "hooks-http", "", "An HTTP endpoint to which hook events will be sent to")
|
||||||
|
|
|
@ -34,6 +34,7 @@ func Serve() {
|
||||||
NotifyTerminatedUploads: true,
|
NotifyTerminatedUploads: true,
|
||||||
NotifyUploadProgress: true,
|
NotifyUploadProgress: true,
|
||||||
NotifyCreatedUploads: true,
|
NotifyCreatedUploads: true,
|
||||||
|
UploadProgressInterval: time.Duration(Flags.ProgressHooksInterval) * time.Millisecond,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := SetupPreHooks(&config); err != nil {
|
if err := SetupPreHooks(&config); err != nil {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config provides a way to configure the Handler depending on your needs.
|
// 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
|
// NotifyCreatedUploads indicates whether sending notifications about
|
||||||
// the upload having been created using the CreatedUploads channel should be enabled.
|
// the upload having been created using the CreatedUploads channel should be enabled.
|
||||||
NotifyCreatedUploads bool
|
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 is the logger to use internally, mostly for printing requests.
|
||||||
Logger *log.Logger
|
Logger *log.Logger
|
||||||
// Respect the X-Forwarded-Host, X-Forwarded-Proto and Forwarded headers
|
// 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")
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -984,7 +984,7 @@ func (handler *UnroutedHandler) sendProgressMessages(hook HookEvent, reader *bod
|
||||||
previousOffset = hook.Upload.Offset
|
previousOffset = hook.Upload.Offset
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
case <-time.After(1 * time.Second):
|
case <-time.After(handler.config.UploadProgressInterval):
|
||||||
hook.Upload.Offset = originalOffset + reader.bytesRead()
|
hook.Upload.Offset = originalOffset + reader.bytesRead()
|
||||||
if hook.Upload.Offset != previousOffset {
|
if hook.Upload.Offset != previousOffset {
|
||||||
handler.UploadProgress <- hook
|
handler.UploadProgress <- hook
|
||||||
|
|
Loading…
Reference in New Issue