fix(tasks): 任务队列 - 限制缓存回源并修复并发租约与过期写入
This commit is contained in:
1 parent
1ff5e5cada
commit
bf0c4454fa
23 files changed
+1098
-59
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -187,8 +188,14 @@ func (s *Service) RuntimePolicy() (RuntimePolicySetting, error) {
|
||||
}
|
||||
|
||||
func (s *Service) runtimeConcurrencySetting() (RuntimeTaskPolicy, error) {
|
||||
policy, err := s.RuntimePolicy()
|
||||
return policy.Task, err
|
||||
s.initReadCaches()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
return s.concurrencyReadCache.get(ctx, runtimePolicySettingKey, func(ctx context.Context) (RuntimeTaskPolicy, int, error) {
|
||||
reader := &Service{repo: s.repo.WithContext(ctx)}
|
||||
policy, err := reader.RuntimePolicy()
|
||||
return policy.Task, 256, err
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Service) PublicRuntimeLimits() (*PublicRuntimeLimits, error) {
|
||||
@@ -243,6 +250,8 @@ func (s *Service) UpdateRuntimePolicySetting(actor *model.User, value RuntimePol
|
||||
if err := s.repo.SaveSystemSetting(&setting); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.initReadCaches()
|
||||
s.concurrencyReadCache.clear()
|
||||
if err := s.appendAdminAudit(actor, "runtime_policy.update", "system_setting", runtimePolicySettingKey, "更新资源与请求策略", map[string]any{"before": before, "after": value}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -260,6 +269,8 @@ func (s *Service) ResetRuntimePolicySetting(actor *model.User) (*PublicRuntimePo
|
||||
if err := s.repo.DeleteSystemSetting(runtimePolicySettingKey); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.initReadCaches()
|
||||
s.concurrencyReadCache.clear()
|
||||
after := defaultRuntimePolicy()
|
||||
if err := s.appendAdminAudit(actor, "runtime_policy.reset", "system_setting", runtimePolicySettingKey, "重置资源与请求策略", map[string]any{"before": before, "after": after}); err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in new issue
Block a user