From abaa8e90b2b91b7e536dfa02030f8d747611d45d Mon Sep 17 00:00:00 2001 From: Aykhan Shahsuvarov Date: Tue, 1 Apr 2025 21:09:17 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=94=A7=20Add=20'run'=20and=20'fmt'=20?= =?UTF-8?q?commands=20to=20Taskfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Taskfile.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Taskfile.yaml b/Taskfile.yaml index f199bd9..d9ee779 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -18,10 +18,14 @@ vars: archs: [386, amd64, arm64] tasks: + run: go run main.go + lint: golangci-lint run build: go build -ldflags "-s -w" -o "dodo" + fmt: gofmt -w -d . + build-all: silent: true cmds: From 415d0130ce6d0c55e9b6934475984e90e94b641d Mon Sep 17 00:00:00 2001 From: Aykhan Shahsuvarov Date: Tue, 1 Apr 2025 21:10:02 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=A8=20Move=20duration=20cancel=20l?= =?UTF-8?q?ogic=20to=20requests=20package?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 5 ----- requests/run.go | 7 +++++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 36a0b2d..5e99a86 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,6 @@ import ( "os" "os/signal" "syscall" - "time" "github.com/aykhans/dodo/config" "github.com/aykhans/dodo/requests" @@ -50,10 +49,6 @@ func main() { ctx, cancel := context.WithCancel(context.Background()) go listenForTermination(func() { cancel() }) - if requestConf.Duration > 0 { - time.AfterFunc(requestConf.Duration, func() { cancel() }) - } - responses, err := requests.Run(ctx, requestConf) if err != nil { if err == types.ErrInterrupt { diff --git a/requests/run.go b/requests/run.go index a076671..d3937dd 100644 --- a/requests/run.go +++ b/requests/run.go @@ -20,6 +20,9 @@ import ( // - ctx: The context for managing request lifecycle and cancellation. // - requestConfig: The configuration for the request, including timeout, proxies, and other settings. func Run(ctx context.Context, requestConfig *config.RequestConfig) (Responses, error) { + ctx, cancel := context.WithCancel(ctx) + defer cancel() + clients := getClients( ctx, requestConfig.Timeout, @@ -31,6 +34,10 @@ func Run(ctx context.Context, requestConfig *config.RequestConfig) (Responses, e return nil, types.ErrInterrupt } + if requestConfig.Duration > 0 { + time.AfterFunc(requestConfig.Duration, func() { cancel() }) + } + responses := releaseDodos(ctx, requestConfig, clients) if ctx.Err() != nil && len(responses) == 0 { return nil, types.ErrInterrupt