Подключите RabbitMQ и отдельный обработчик заданий

This commit is contained in:
2026-11-18 15:33:33 +03:00
parent 752f29573b
commit 2dc566e6ec
19 changed files with 818 additions and 14 deletions
+41
View File
@@ -0,0 +1,41 @@
package config
import (
"fmt"
"strconv"
"time"
)
type Jobs struct {
URL string
Concurrency, MaxAttempts int
Timeout time.Duration
}
func LoadJobs(lookup Lookup) (Jobs, error) {
url, err := secret(lookup, "BROKER_URL_FILE")
if err != nil {
return Jobs{}, err
}
c := Jobs{URL: url, Concurrency: 2, MaxAttempts: 5}
seconds := 60
for _, p := range []struct {
key string
value *int
max int
}{
{"WORKER_CONCURRENCY", &c.Concurrency, 2},
{"JOB_MAX_ATTEMPTS", &c.MaxAttempts, 100},
{"JOB_TIMEOUT_SECONDS", &seconds, 3600},
} {
if s, ok := lookup(p.key); ok {
n, err := strconv.Atoi(s)
if err != nil || n < 1 || n > p.max {
return Jobs{}, fmt.Errorf("%s must be between 1 and %d", p.key, p.max)
}
*p.value = n
}
}
c.Timeout = time.Duration(seconds) * time.Second
return c, nil
}