Ability to enable/disable locks
This commit is contained in:
@@ -3,6 +3,7 @@ host: 0.0.0.0
|
|||||||
port: 3001
|
port: 3001
|
||||||
redis: ${REDIS_URL} # Use an environment variable to define the Redis URL
|
redis: ${REDIS_URL} # Use an environment variable to define the Redis URL
|
||||||
cache:
|
cache:
|
||||||
|
enable_locks: true
|
||||||
java_status_duration: 1m
|
java_status_duration: 1m
|
||||||
bedrock_status_duration: 1m
|
bedrock_status_duration: 1m
|
||||||
icon_duration: 24h
|
icon_duration: 24h
|
||||||
@@ -17,6 +17,7 @@ var (
|
|||||||
Port: 3001,
|
Port: 3001,
|
||||||
Redis: nil,
|
Redis: nil,
|
||||||
Cache: ConfigCache{
|
Cache: ConfigCache{
|
||||||
|
EnableLocks: true,
|
||||||
JavaStatusDuration: time.Minute,
|
JavaStatusDuration: time.Minute,
|
||||||
BedrockStatusDuration: time.Minute,
|
BedrockStatusDuration: time.Minute,
|
||||||
IconDuration: time.Minute * 15,
|
IconDuration: time.Minute * 15,
|
||||||
@@ -35,9 +36,10 @@ type Config struct {
|
|||||||
|
|
||||||
// ConfigCache represents the caching durations of various responses.
|
// ConfigCache represents the caching durations of various responses.
|
||||||
type ConfigCache struct {
|
type ConfigCache struct {
|
||||||
JavaStatusDuration time.Duration `yaml:"java_status_duration" json:"java_status_duration"`
|
EnableLocks bool `yaml:"enable_locks"`
|
||||||
BedrockStatusDuration time.Duration `yaml:"bedrock_status_duration" json:"bedrock_status_duration"`
|
JavaStatusDuration time.Duration `yaml:"java_status_duration"`
|
||||||
IconDuration time.Duration `yaml:"icon_duration" json:"icon_duration"`
|
BedrockStatusDuration time.Duration `yaml:"bedrock_status_duration"`
|
||||||
|
IconDuration time.Duration `yaml:"icon_duration"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadFile reads the configuration from the given file and overrides values using environment variables.
|
// ReadFile reads the configuration from the given file and overrides values using environment variables.
|
||||||
|
|||||||
@@ -116,10 +116,12 @@ type Plugin struct {
|
|||||||
func GetJavaStatus(host string, port uint16, enableQuery bool) (*JavaStatusResponse, time.Duration, error) {
|
func GetJavaStatus(host string, port uint16, enableQuery bool) (*JavaStatusResponse, time.Duration, error) {
|
||||||
cacheKey := fmt.Sprintf("java:%v-%s-%d", enableQuery, host, port)
|
cacheKey := fmt.Sprintf("java:%v-%s-%d", enableQuery, host, port)
|
||||||
|
|
||||||
mutex := r.NewMutex(fmt.Sprintf("java-lock:%v-%s-%d", enableQuery, host, port))
|
if conf.Cache.EnableLocks {
|
||||||
mutex.Lock()
|
mutex := r.NewMutex(fmt.Sprintf("java-lock:%v-%s-%d", enableQuery, host, port))
|
||||||
|
mutex.Lock()
|
||||||
|
|
||||||
defer mutex.Unlock()
|
defer mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
cache, ttl, err := r.Get(cacheKey)
|
cache, ttl, err := r.Get(cacheKey)
|
||||||
|
|
||||||
@@ -154,10 +156,12 @@ func GetJavaStatus(host string, port uint16, enableQuery bool) (*JavaStatusRespo
|
|||||||
func GetBedrockStatus(host string, port uint16) (*BedrockStatusResponse, time.Duration, error) {
|
func GetBedrockStatus(host string, port uint16) (*BedrockStatusResponse, time.Duration, error) {
|
||||||
cacheKey := fmt.Sprintf("bedrock:%s-%d", host, port)
|
cacheKey := fmt.Sprintf("bedrock:%s-%d", host, port)
|
||||||
|
|
||||||
mutex := r.NewMutex(fmt.Sprintf("bedrock-lock:%s-%d", host, port))
|
if conf.Cache.EnableLocks {
|
||||||
mutex.Lock()
|
mutex := r.NewMutex(fmt.Sprintf("bedrock-lock:%s-%d", host, port))
|
||||||
|
mutex.Lock()
|
||||||
|
|
||||||
defer mutex.Unlock()
|
defer mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
cache, ttl, err := r.Get(cacheKey)
|
cache, ttl, err := r.Get(cacheKey)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user