From f65f0d86aa570ceeb7edc5212a181213ac288f6a Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 24 May 2023 18:36:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=A1=E5=88=92=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=AF=8F=E9=9A=94=20n=20=E7=A7=92=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=20(#1132)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/dto/cronjob.go | 3 + backend/app/model/cronjob.go | 1 + backend/app/service/cornjob.go | 2 + backend/init/migration/migrate.go | 1 + backend/init/migration/migrations/init.go | 12 +++- frontend/src/api/interface/cronjob.ts | 3 + frontend/src/lang/modules/en.ts | 2 + frontend/src/lang/modules/zh.ts | 2 + frontend/src/views/cronjob/index.vue | 2 + frontend/src/views/cronjob/operate/index.vue | 71 ++++++++++++++------ 10 files changed, 77 insertions(+), 22 deletions(-) diff --git a/backend/app/dto/cronjob.go b/backend/app/dto/cronjob.go index e72efb983..45d755f7f 100644 --- a/backend/app/dto/cronjob.go +++ b/backend/app/dto/cronjob.go @@ -10,6 +10,7 @@ type CronjobCreate struct { Day int `json:"day" validate:"number"` Hour int `json:"hour" validate:"number"` Minute int `json:"minute" validate:"number"` + Second int `json:"second" validate:"number"` Script string `json:"script"` Website string `json:"website"` @@ -30,6 +31,7 @@ type CronjobUpdate struct { Day int `json:"day" validate:"number"` Hour int `json:"hour" validate:"number"` Minute int `json:"minute" validate:"number"` + Second int `json:"second" validate:"number"` Script string `json:"script"` Website string `json:"website"` @@ -71,6 +73,7 @@ type CronjobInfo struct { Day int `json:"day"` Hour int `json:"hour"` Minute int `json:"minute"` + Second int `json:"second"` Script string `json:"script"` Website string `json:"website"` diff --git a/backend/app/model/cronjob.go b/backend/app/model/cronjob.go index 0aae20e48..befacb5cb 100644 --- a/backend/app/model/cronjob.go +++ b/backend/app/model/cronjob.go @@ -13,6 +13,7 @@ type Cronjob struct { Day uint64 `gorm:"type:decimal" json:"day"` Hour uint64 `gorm:"type:decimal" json:"hour"` Minute uint64 `gorm:"type:decimal" json:"minute"` + Second uint64 `gorm:"type:decimal" json:"second"` Script string `gorm:"longtext" json:"script"` Website string `gorm:"type:varchar(64)" json:"website"` diff --git a/backend/app/service/cornjob.go b/backend/app/service/cornjob.go index 0a76ef48e..bd918d306 100644 --- a/backend/app/service/cornjob.go +++ b/backend/app/service/cornjob.go @@ -322,6 +322,8 @@ func loadSpec(cronjob model.Cronjob) string { return fmt.Sprintf("%v * * * *", cronjob.Minute) case "perNMinute": return fmt.Sprintf("@every %vm", cronjob.Minute) + case "perNSecond": + return fmt.Sprintf("@every %vs", cronjob.Second) default: return "" } diff --git a/backend/init/migration/migrate.go b/backend/init/migration/migrate.go index d9733119b..90c37b843 100644 --- a/backend/init/migration/migrate.go +++ b/backend/init/migration/migrate.go @@ -29,6 +29,7 @@ func Init() { migrations.UpdateTableSetting, migrations.UpdateTableAppDetail, migrations.AddBindAndAllowIPs, + migrations.UpdateCronjobWithSecond, }) if err := m.Migrate(); err != nil { global.LOG.Error(err) diff --git a/backend/init/migration/migrations/init.go b/backend/init/migration/migrations/init.go index 9931603f4..ea9009977 100644 --- a/backend/init/migration/migrations/init.go +++ b/backend/init/migration/migrations/init.go @@ -337,7 +337,7 @@ var UpdateTableAppDetail = &gormigrate.Migration{ } var AddBindAndAllowIPs = &gormigrate.Migration{ - ID: "20230414-add-bind-and-allow", + ID: "20230517-add-bind-and-allow", Migrate: func(tx *gorm.DB) error { if err := tx.Create(&model.Setting{Key: "BindDomain", Value: ""}).Error; err != nil { return err @@ -354,3 +354,13 @@ var AddBindAndAllowIPs = &gormigrate.Migration{ return nil }, } + +var UpdateCronjobWithSecond = &gormigrate.Migration{ + ID: "20200524-update-table-cronjob", + Migrate: func(tx *gorm.DB) error { + if err := tx.AutoMigrate(&model.Cronjob{}); err != nil { + return err + } + return nil + }, +} diff --git a/frontend/src/api/interface/cronjob.ts b/frontend/src/api/interface/cronjob.ts index d2dc11c03..08837c358 100644 --- a/frontend/src/api/interface/cronjob.ts +++ b/frontend/src/api/interface/cronjob.ts @@ -10,6 +10,7 @@ export namespace Cronjob { day: number; hour: number; minute: number; + second: number; script: string; website: string; @@ -31,6 +32,7 @@ export namespace Cronjob { day: number; hour: number; minute: number; + second: number; script: string; website: string; @@ -49,6 +51,7 @@ export namespace Cronjob { day: number; hour: number; minute: number; + second: number; script: string; website: string; diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 82fceee3a..38ffe9e06 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -651,12 +651,14 @@ const message = { perDay: 'Every days', perNHour: 'Every N hours', perNMinute: 'Every N minutes', + perNSecond: 'Every N seconds', per: 'Every ', handle: 'Handle', day: 'Day', day1: 'Day', hour: ' Hour', minute: ' Minute', + second: ' Second', monday: 'Monday', tuesday: 'Tuesday', wednesday: 'Wednesday', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 319ef4066..3a2f3609f 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -657,12 +657,14 @@ const message = { perDay: '每天', perNHour: '每隔 N 时', perNMinute: '每隔 N 分钟', + perNSecond: '每隔 N 秒', per: '每隔', handle: '执行', day: '日', day1: '天', hour: '小时', minute: '分钟', + second: '秒', monday: '周一', tuesday: '周二', wednesday: '周三', diff --git a/frontend/src/views/cronjob/index.vue b/frontend/src/views/cronjob/index.vue index 91ee0b1d0..f06cfe492 100644 --- a/frontend/src/views/cronjob/index.vue +++ b/frontend/src/views/cronjob/index.vue @@ -95,6 +95,7 @@ {{ loadZero(row.minute) }} {{ row.minute }}{{ $t('cronjob.minute') }} + {{ row.second }}{{ $t('cronjob.second') }} {{ $t('cronjob.handle') }} @@ -227,6 +228,7 @@ const onOpenDialog = async ( day: 3, hour: 1, minute: 30, + second: 30, keepLocal: true, retainCopies: 7, }, diff --git a/frontend/src/views/cronjob/operate/index.vue b/frontend/src/views/cronjob/operate/index.vue index ede3800ca..5d94dfe4b 100644 --- a/frontend/src/views/cronjob/operate/index.vue +++ b/frontend/src/views/cronjob/operate/index.vue @@ -9,7 +9,7 @@ @@ -27,7 +27,6 @@ @@ -44,7 +43,7 @@ - + - + - + + + + - + @@ -99,7 +100,7 @@
- + @@ -111,7 +112,7 @@ :label="$t('cronjob.sourceDir')" prop="sourceDir" > - + @@ -120,7 +121,7 @@
- + - + { callback(new Error(i18n.global.t('cronjob.cronSpecRule'))); } break; + case 'perNSecond': + if (!Number.isInteger(dialogData.value.rowData!.second)) { + callback(new Error(i18n.global.t('cronjob.cronSpecRule'))); + } + break; } callback(); }; @@ -296,6 +301,7 @@ const specOptions = [ { label: i18n.global.t('cronjob.perNDay'), value: 'perNDay' }, { label: i18n.global.t('cronjob.perNHour'), value: 'perNHour' }, { label: i18n.global.t('cronjob.perNMinute'), value: 'perNMinute' }, + { label: i18n.global.t('cronjob.perNSecond'), value: 'perNSecond' }, ]; const weekOptions = [ { label: i18n.global.t('cronjob.monday'), value: 1 }, @@ -335,6 +341,17 @@ const loadDir = async (path: string) => { dialogData.value.rowData!.sourceDir = path; }; +const hasDay = () => { + return dialogData.value.rowData!.specType === 'perMonth' || dialogData.value.rowData!.specType === 'perNDay'; +}; +const hasHour = () => { + return ( + dialogData.value.rowData!.specType !== 'perHour' && + dialogData.value.rowData!.specType !== 'perNMinute' && + dialogData.value.rowData!.specType !== 'perNSecond' + ); +}; + const changeType = () => { switch (dialogData.value.rowData!.type) { case 'shell': @@ -430,6 +447,8 @@ function checkScript() { return row.hour > 0 && row.hour < 8784 && row.minute >= 0 && row.minute < 60; case 'perNMinute': return row.minute > 0 && row.minute < 527040; + case 'perNSecond': + return row.second > 0 && row.second < 31622400; } } @@ -438,6 +457,7 @@ const onSubmit = async (formEl: FormInstance | undefined) => { dialogData.value.rowData.day = Number(dialogData.value.rowData.day); dialogData.value.rowData.hour = Number(dialogData.value.rowData.hour); dialogData.value.rowData.minute = Number(dialogData.value.rowData.minute); + dialogData.value.rowData.second = Number(dialogData.value.rowData.second); if (!checkScript()) { MsgError(i18n.global.t('cronjob.cronSpecHelper')); return; @@ -463,3 +483,12 @@ defineExpose({ acceptParams, }); +