optional store traffic time

This commit is contained in:
Alireza Ahmadi
2024-04-25 21:10:02 +02:00
parent abb869c75b
commit 9a02e6593c
10 changed files with 41 additions and 6 deletions
+7 -1
View File
@@ -51,7 +51,13 @@ func (a *APP) Start() error {
if err != nil { if err != nil {
return err return err
} }
err = a.cronJob.Start(loc)
trafficAge, err := a.SettingService.GetTrafficAge()
if err != nil {
return err
}
err = a.cronJob.Start(loc, trafficAge)
if err != nil { if err != nil {
return err return err
} }
+2 -2
View File
@@ -14,7 +14,7 @@ func NewCronJob() *CronJob {
return &CronJob{} return &CronJob{}
} }
func (c *CronJob) Start(loc *time.Location) error { func (c *CronJob) Start(loc *time.Location, trafficAge int) error {
c.cron = cron.New(cron.WithLocation(loc), cron.WithSeconds()) c.cron = cron.New(cron.WithLocation(loc), cron.WithSeconds())
c.cron.Start() c.cron.Start()
@@ -24,7 +24,7 @@ func (c *CronJob) Start(loc *time.Location) error {
// Start expiry job // Start expiry job
c.cron.AddJob("@every 1m", NewDepleteJob()) c.cron.AddJob("@every 1m", NewDepleteJob())
// Start deleting old stats // Start deleting old stats
c.cron.AddJob("@daily", NewDelStatsJob()) c.cron.AddJob("@daily", NewDelStatsJob(trafficAge))
}() }()
return nil return nil
+6 -3
View File
@@ -7,14 +7,17 @@ import (
type DelStatsJob struct { type DelStatsJob struct {
service.StatsService service.StatsService
trafficAge int
} }
func NewDelStatsJob() *DelStatsJob { func NewDelStatsJob(ta int) *DelStatsJob {
return &DelStatsJob{} return &DelStatsJob{
trafficAge: ta,
}
} }
func (s *DelStatsJob) Run() { func (s *DelStatsJob) Run() {
err := s.StatsService.DelOldStats(30) err := s.StatsService.DelOldStats(s.trafficAge)
if err != nil { if err != nil {
logger.Warning("Deleting old statistics failed: ", err) logger.Warning("Deleting old statistics failed: ", err)
return return
+5
View File
@@ -24,6 +24,7 @@ var defaultValueMap = map[string]string{
"webPath": "/app/", "webPath": "/app/",
"webURI": "", "webURI": "",
"sessionMaxAge": "0", "sessionMaxAge": "0",
"trafficAge": "30",
"timeLocation": "Asia/Tehran", "timeLocation": "Asia/Tehran",
"subListen": "", "subListen": "",
"subPort": "2096", "subPort": "2096",
@@ -204,6 +205,10 @@ func (s *SettingService) GetSessionMaxAge() (int, error) {
return s.getInt("sessionMaxAge") return s.getInt("sessionMaxAge")
} }
func (s *SettingService) GetTrafficAge() (int, error) {
return s.getInt("trafficAge")
}
func (s *SettingService) GetTimeLocation() (*time.Location, error) { func (s *SettingService) GetTimeLocation() (*time.Location, error) {
l, err := s.getString("timeLocation") l, err := s.getString("timeLocation")
if err != nil { if err != nil {
+1
View File
@@ -102,6 +102,7 @@ export default {
sslCert: "SSL Certificate Path", sslCert: "SSL Certificate Path",
webUri: "Panel URI", webUri: "Panel URI",
sessionAge: "Session Maximum Age", sessionAge: "Session Maximum Age",
trafficAge: "Traffic Maximum Age",
timeLoc: "Timezone Location", timeLoc: "Timezone Location",
subEncode: "Enable Encoding", subEncode: "Enable Encoding",
subInfo: "Enable Client Info", subInfo: "Enable Client Info",
+1
View File
@@ -102,6 +102,7 @@ export default {
sslCert: "مسیر فایل گواهی", sslCert: "مسیر فایل گواهی",
webUri: "آدرس نهایی پنل", webUri: "آدرس نهایی پنل",
sessionAge: "بیشینه زمان لاگین ماندن", sessionAge: "بیشینه زمان لاگین ماندن",
trafficAge: "بیشینه زمان ذخیره ترافیک",
timeLoc: "منطقه زمانی", timeLoc: "منطقه زمانی",
subEncode: "رمزگذاری", subEncode: "رمزگذاری",
subInfo: "نمایش اطلاعات کاربر", subInfo: "نمایش اطلاعات کاربر",
+1
View File
@@ -102,6 +102,7 @@ export default {
sslCert: "Đường dẫn chứng chỉ SSL", sslCert: "Đường dẫn chứng chỉ SSL",
webUri: "URI bảng điều khiển", webUri: "URI bảng điều khiển",
sessionAge: "Tuổi tối đa của phiên", sessionAge: "Tuổi tối đa của phiên",
trafficAge: "Tuổi lưu thông tối đa",
timeLoc: "Vị trí múi giờ", timeLoc: "Vị trí múi giờ",
subEncode: "Kích hoạt mã hóa", subEncode: "Kích hoạt mã hóa",
subInfo: "Kích hoạt thông tin khách hàng", subInfo: "Kích hoạt thông tin khách hàng",
+1
View File
@@ -102,6 +102,7 @@ export default {
sslCert: "SSL 证书 (cert) 路径", sslCert: "SSL 证书 (cert) 路径",
webUri: "面板 URI", webUri: "面板 URI",
sessionAge: "会话最大连接数", sessionAge: "会话最大连接数",
trafficAge: "流量最大年龄",
timeLoc: "时区", timeLoc: "时区",
subEncode: "启用编码", subEncode: "启用编码",
subInfo: "启用用户信息", subInfo: "启用用户信息",
+1
View File
@@ -102,6 +102,7 @@ export default {
sslCert: "SSL 證書 (cert) 路徑", sslCert: "SSL 證書 (cert) 路徑",
webUri: "面板 URI", webUri: "面板 URI",
sessionAge: "會話最大連接數", sessionAge: "會話最大連接數",
trafficAge: "流量最大年齡",
timeLoc: "時區", timeLoc: "時區",
subEncode: "啟用編碼", subEncode: "啟用編碼",
subInfo: "啟用用戶信息", subInfo: "啟用用戶信息",
+16
View File
@@ -52,6 +52,16 @@
type="number" type="number"
v-model.number="sessionMaxAge" v-model.number="sessionMaxAge"
:label="$t('setting.sessionAge')" :label="$t('setting.sessionAge')"
:suffix="$t('date.h')"
hide-details
></v-text-field>
</v-col>
<v-col cols="12" sm="6" md="4">
<v-text-field
type="number"
v-model.number="trafficAge"
:label="$t('setting.trafficAge')"
:suffix="$t('date.d')"
hide-details hide-details
></v-text-field> ></v-text-field>
</v-col> </v-col>
@@ -152,6 +162,7 @@ const settings = ref({
webPath: "/app/", webPath: "/app/",
webURI: "", webURI: "",
sessionMaxAge: "0", sessionMaxAge: "0",
trafficAge: "30",
timeLocation: "Asia/Tehran", timeLocation: "Asia/Tehran",
subListen: "", subListen: "",
subPort: "2096", subPort: "2096",
@@ -246,6 +257,11 @@ const sessionMaxAge = computed({
set: (v:number) => { settings.value.sessionMaxAge = v.toString() } set: (v:number) => { settings.value.sessionMaxAge = v.toString() }
}) })
const trafficAge = computed({
get: () => { return parseInt(settings.value.trafficAge) },
set: (v:number) => { settings.value.trafficAge = v.toString() }
})
const subPort = computed({ const subPort = computed({
get: () => { return parseInt(settings.value.subPort) }, get: () => { return parseInt(settings.value.subPort) },
set: (v:number) => { settings.value.subPort = v.toString() } set: (v:number) => { settings.value.subPort = v.toString() }