Some checks are pending
Security Checks / security (push) Waiting to run
统一 frontend、backend、test、test-log 和 out 目录,更新构建、部署及测试入口;纳入配置管理兼容与首次安全引导修复;排除本机配置、密钥和测试产物。
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package verification
|
|
|
|
import (
|
|
"time"
|
|
|
|
"xorm.io/xorm"
|
|
)
|
|
|
|
const DefaultCleanupInterval = time.Minute
|
|
|
|
type Runtime struct {
|
|
Store *Store
|
|
Events *EventStore
|
|
RateLimits *PersistentRateLimiter
|
|
cleanup *CleanupRunner
|
|
operationalCleanup *OperationalCleanupRunner
|
|
}
|
|
|
|
func NewRuntime(maxEntries int) (*Runtime, error) {
|
|
return NewRuntimeWithEventStore(maxEntries, nil)
|
|
}
|
|
|
|
func NewRuntimeWithEventStore(maxEntries int, engine *xorm.Engine) (*Runtime, error) {
|
|
store, err := NewStore(maxEntries)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
runtime := &Runtime{Store: store, cleanup: NewCleanupRunner(store)}
|
|
if engine != nil {
|
|
events, eventErr := NewEventStore(engine)
|
|
if eventErr != nil {
|
|
return nil, eventErr
|
|
}
|
|
runtime.Events = events
|
|
rateLimits, limitErr := NewPersistentRateLimiter(engine)
|
|
if limitErr != nil {
|
|
return nil, limitErr
|
|
}
|
|
runtime.RateLimits = rateLimits
|
|
runtime.operationalCleanup = NewOperationalCleanupRunner(events, rateLimits)
|
|
runtime.operationalCleanup.Start()
|
|
}
|
|
if err := runtime.cleanup.Start(DefaultCleanupInterval); err != nil {
|
|
if runtime.operationalCleanup != nil {
|
|
runtime.operationalCleanup.Stop()
|
|
}
|
|
return nil, err
|
|
}
|
|
return runtime, nil
|
|
}
|
|
|
|
func (r *Runtime) Stop() {
|
|
if r == nil {
|
|
return
|
|
}
|
|
if r.cleanup != nil {
|
|
r.cleanup.Stop()
|
|
}
|
|
if r.operationalCleanup != nil {
|
|
r.operationalCleanup.Stop()
|
|
}
|
|
}
|