mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
fix(actions): reject if client is disabled (#1626)
* fix(actions): error on disabled client * fix(actions): sql scan args * refactor: download client cache for actions * fix: tests client store * fix: tests client store and int conversion * fix: tests revert findbyid ctx timeout * fix: tests row.err * feat: add logging to download client cache
This commit is contained in:
parent
77e1c2c305
commit
861f30c144
30 changed files with 928 additions and 680 deletions
48
internal/download_client/cache.go
Normal file
48
internal/download_client/cache.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package download_client
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
)
|
||||
|
||||
type ClientCacheStore interface {
|
||||
Set(id int32, client *domain.DownloadClient)
|
||||
Get(id int32) *domain.DownloadClient
|
||||
Pop(id int32)
|
||||
}
|
||||
|
||||
type ClientCache struct {
|
||||
mu sync.RWMutex
|
||||
clients map[int32]*domain.DownloadClient
|
||||
}
|
||||
|
||||
func NewClientCache() *ClientCache {
|
||||
return &ClientCache{
|
||||
clients: make(map[int32]*domain.DownloadClient),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ClientCache) Set(id int32, client *domain.DownloadClient) {
|
||||
if client != nil {
|
||||
c.mu.Lock()
|
||||
c.clients[id] = client
|
||||
c.mu.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ClientCache) Get(id int32) *domain.DownloadClient {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
v, ok := c.clients[id]
|
||||
if ok {
|
||||
return v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ClientCache) Pop(id int32) {
|
||||
c.mu.Lock()
|
||||
delete(c.clients, id)
|
||||
c.mu.Unlock()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue