handler: Refactor logging of UploadFinished and UploadTerminated into handler

This commit is contained in:
Marius Kleidl 2023-06-09 08:30:42 +02:00
parent a75c24996f
commit d5eca08944
No known key found for this signature in database
GPG Key ID: 2F8AC5B12D755265
2 changed files with 2 additions and 9 deletions

View File

@ -1,7 +1,6 @@
package cli
import (
"strconv"
"strings"
"github.com/tus/tusd/v2/cmd/tusd/cli/hooks"
@ -125,14 +124,6 @@ func invokeHookSync(typ hooks.HookType, event handler.HookEvent) (httpRes handle
MetricsHookInvocationsTotal.WithLabelValues(string(typ)).Add(1)
id := event.Upload.ID
size := event.Upload.Size
switch typ {
case hooks.HookPostFinish:
logEv(stdout, "UploadFinished", "id", id, "size", strconv.FormatInt(size, 10))
case hooks.HookPostTerminate:
logEv(stdout, "UploadTerminated", "id", id)
}
if hookHandler == nil {
return httpRes, nil

View File

@ -678,6 +678,7 @@ func (handler *UnroutedHandler) finishUploadIfComplete(c *httpContext, resp HTTP
resp = resp.MergeWith(resp2)
}
handler.log("UploadFinished", "id", info.ID, "size", strconv.FormatInt(info.Size, 10))
handler.Metrics.incUploadsFinished()
// ... send the info out to the channel
@ -882,6 +883,7 @@ func (handler *UnroutedHandler) terminateUpload(c *httpContext, upload Upload, i
handler.TerminatedUploads <- newHookEvent(info, c.req)
}
handler.log("UploadTerminated", "id", info.ID)
handler.Metrics.incUploadsTerminated()
return nil