feat: add option for delaying task get requests
All checks were successful
release-tag / release (push) Successful in 2m3s
All checks were successful
release-tag / release (push) Successful in 2m3s
This commit is contained in:
parent
5a40fb593c
commit
5f60eb8752
12
api/api.go
12
api/api.go
@ -35,19 +35,19 @@ type RegistryStats struct {
|
|||||||
|
|
||||||
type TaskRegistry struct {
|
type TaskRegistry struct {
|
||||||
mu *sync.RWMutex
|
mu *sync.RWMutex
|
||||||
lifetime time.Duration
|
config *config.Config
|
||||||
tasks map[uint32]*Task
|
tasks map[uint32]*Task
|
||||||
idCounter uint32
|
idCounter uint32
|
||||||
api *sati.Api
|
api *sati.Api
|
||||||
stats RegistryStats
|
stats RegistryStats
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTaskRegistry(api *sati.Api, lifetime time.Duration) *TaskRegistry {
|
func NewTaskRegistry(api *sati.Api, config *config.Config) *TaskRegistry {
|
||||||
return &TaskRegistry{
|
return &TaskRegistry{
|
||||||
mu: &sync.RWMutex{},
|
mu: &sync.RWMutex{},
|
||||||
tasks: map[uint32]*Task{},
|
tasks: map[uint32]*Task{},
|
||||||
api: api,
|
api: api,
|
||||||
lifetime: lifetime,
|
config: config,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ func (t *TaskRegistry) CreateTask(task sati.AnyTask) uint32 {
|
|||||||
entry.EndTime = time.Now().Unix()
|
entry.EndTime = time.Now().Unix()
|
||||||
t.mu.Unlock()
|
t.mu.Unlock()
|
||||||
|
|
||||||
time.Sleep(t.lifetime)
|
time.Sleep(time.Millisecond * time.Duration(t.config.TaskLifetime))
|
||||||
t.mu.Lock()
|
t.mu.Lock()
|
||||||
delete(t.tasks, id)
|
delete(t.tasks, id)
|
||||||
t.mu.Unlock()
|
t.mu.Unlock()
|
||||||
@ -98,6 +98,10 @@ func (t *TaskRegistry) Stats() RegistryStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TaskRegistry) Get(id uint32) *Task {
|
func (t *TaskRegistry) Get(id uint32) *Task {
|
||||||
|
if t.config.TaskGetDelay != 0 {
|
||||||
|
time.Sleep(time.Millisecond * time.Duration(t.config.TaskGetDelay))
|
||||||
|
}
|
||||||
|
|
||||||
t.mu.RLock()
|
t.mu.RLock()
|
||||||
defer t.mu.RUnlock()
|
defer t.mu.RUnlock()
|
||||||
task := t.tasks[id]
|
task := t.tasks[id]
|
||||||
|
@ -16,6 +16,8 @@ type Config struct {
|
|||||||
TlsKeyPath string `json:"tlsKeyPath"`
|
TlsKeyPath string `json:"tlsKeyPath"`
|
||||||
Host string `json:"host"`
|
Host string `json:"host"`
|
||||||
TlsHost string `json:"tlsHost"`
|
TlsHost string `json:"tlsHost"`
|
||||||
|
TaskLifetime int64 `json:"taskLifetime"`
|
||||||
|
TaskGetDelay int64 `json:"taskGetDelay"`
|
||||||
AntiGateV2 struct {
|
AntiGateV2 struct {
|
||||||
TurnstileUserAgent string `json:"turnstileUserAgent"`
|
TurnstileUserAgent string `json:"turnstileUserAgent"`
|
||||||
Ip string `json:"ip"`
|
Ip string `json:"ip"`
|
||||||
@ -32,6 +34,8 @@ func Default() *Config {
|
|||||||
TlsKeyPath: "./data/ca.key",
|
TlsKeyPath: "./data/ca.key",
|
||||||
Host: "127.0.0.1:80",
|
Host: "127.0.0.1:80",
|
||||||
TlsHost: "127.0.0.1:443",
|
TlsHost: "127.0.0.1:443",
|
||||||
|
TaskLifetime: 60000,
|
||||||
|
TaskGetDelay: 0,
|
||||||
AntiGateV2: struct {
|
AntiGateV2: struct {
|
||||||
TurnstileUserAgent string `json:"turnstileUserAgent"`
|
TurnstileUserAgent string `json:"turnstileUserAgent"`
|
||||||
Ip string `json:"ip"`
|
Ip string `json:"ip"`
|
||||||
|
2
main.go
2
main.go
@ -289,7 +289,7 @@ func main() {
|
|||||||
satiConfig.Debug = cfg.Debug
|
satiConfig.Debug = cfg.Debug
|
||||||
satiApi := sati.NewApi(satiConfig)
|
satiApi := sati.NewApi(satiConfig)
|
||||||
|
|
||||||
registry := api.NewTaskRegistry(satiApi, time.Minute)
|
registry := api.NewTaskRegistry(satiApi, cfg)
|
||||||
|
|
||||||
ctx := api.ApiContext{
|
ctx := api.ApiContext{
|
||||||
Config: cfg,
|
Config: cfg,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user