Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuang-Minh Nguyen <qmnguyen@gitlab.com>2023-03-08 17:23:11 +0300
committerQuang-Minh Nguyen <qmnguyen@gitlab.com>2023-03-15 13:06:33 +0300
commit1b7787e9967951aa86db507cab60bc96d0953250 (patch)
tree24db85f69eed76e96e90344c3d8afba789232b24 /internal/command/option.go
parentd4c090d0100aed63563add9e92645bccb5c9b399 (diff)
Add multiple finalizers support to internal/command
When spawning a command, we support adding a finalizer option via `command.WithFinalizer`. Originally, there is only one finalizer. To prepare for trace2 integration, Git command factory needs to find a way to hook to when after a command finishes. Finalizer is a good way to achieve this purpose. Unfortunately, it's not easy to create a wrapper function then trigger the pre-existing finalizer if any. So, expanding this option to support multiple finalizers is a good approach. This commit also adds context to the function signature of finalizer.
Diffstat (limited to 'internal/command/option.go')
-rw-r--r--internal/command/option.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/internal/command/option.go b/internal/command/option.go
index 8f1d64f1d..862dc8d83 100644
--- a/internal/command/option.go
+++ b/internal/command/option.go
@@ -1,6 +1,7 @@
package command
import (
+ "context"
"io"
"gitlab.com/gitlab-org/gitaly/v15/internal/cgroups"
@@ -13,7 +14,7 @@ type config struct {
dir string
environment []string
- finalizer func(*Command)
+ finalizers []func(context.Context, *Command)
commandName string
subcommandName string
@@ -97,8 +98,8 @@ func WithCgroup(cgroupsManager cgroups.Manager, opts ...cgroups.AddCommandOption
// WithFinalizer sets up the finalizer to be run when the command is being wrapped up. It will be
// called after `Wait()` has returned.
-func WithFinalizer(finalizer func(*Command)) Option {
+func WithFinalizer(finalizer func(context.Context, *Command)) Option {
return func(cfg *config) {
- cfg.finalizer = finalizer
+ cfg.finalizers = append(cfg.finalizers, finalizer)
}
}