Merge pull request #103 from aykhans/chore/general-refactoring

General refactoring
This commit is contained in:
Aykhan Shahsuvarov 2025-04-03 04:11:38 +04:00 committed by GitHub
commit f5a29a2657
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 5 deletions

View File

@ -18,10 +18,14 @@ vars:
archs: [386, amd64, arm64] archs: [386, amd64, arm64]
tasks: tasks:
run: go run main.go
lint: golangci-lint run lint: golangci-lint run
build: go build -ldflags "-s -w" -o "dodo" build: go build -ldflags "-s -w" -o "dodo"
fmt: gofmt -w -d .
build-all: build-all:
silent: true silent: true
cmds: cmds:

View File

@ -7,7 +7,6 @@ import (
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
"time"
"github.com/aykhans/dodo/config" "github.com/aykhans/dodo/config"
"github.com/aykhans/dodo/requests" "github.com/aykhans/dodo/requests"
@ -50,10 +49,6 @@ func main() {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
go listenForTermination(func() { cancel() }) go listenForTermination(func() { cancel() })
if requestConf.Duration > 0 {
time.AfterFunc(requestConf.Duration, func() { cancel() })
}
responses, err := requests.Run(ctx, requestConf) responses, err := requests.Run(ctx, requestConf)
if err != nil { if err != nil {
if err == types.ErrInterrupt { if err == types.ErrInterrupt {

View File

@ -20,6 +20,9 @@ import (
// - ctx: The context for managing request lifecycle and cancellation. // - ctx: The context for managing request lifecycle and cancellation.
// - requestConfig: The configuration for the request, including timeout, proxies, and other settings. // - requestConfig: The configuration for the request, including timeout, proxies, and other settings.
func Run(ctx context.Context, requestConfig *config.RequestConfig) (Responses, error) { func Run(ctx context.Context, requestConfig *config.RequestConfig) (Responses, error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
clients := getClients( clients := getClients(
ctx, ctx,
requestConfig.Timeout, requestConfig.Timeout,
@ -31,6 +34,10 @@ func Run(ctx context.Context, requestConfig *config.RequestConfig) (Responses, e
return nil, types.ErrInterrupt return nil, types.ErrInterrupt
} }
if requestConfig.Duration > 0 {
time.AfterFunc(requestConfig.Duration, func() { cancel() })
}
responses := releaseDodos(ctx, requestConfig, clients) responses := releaseDodos(ctx, requestConfig, clients)
if ctx.Err() != nil && len(responses) == 0 { if ctx.Err() != nil && len(responses) == 0 {
return nil, types.ErrInterrupt return nil, types.ErrInterrupt