mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-12-25 16:59:20 +08:00
fix: Fix the issue where cronjob expressions do not support commas (#10493)
Refs #9748
This commit is contained in:
parent
8f0c84c2a5
commit
c4b3efeb9d
5 changed files with 29 additions and 7 deletions
|
|
@ -604,7 +604,7 @@ func (u *CronjobService) StartJob(cronjob *model.Cronjob, isUpdate bool) (string
|
|||
global.Cron.Remove(cron.EntryID(idItem))
|
||||
}
|
||||
}
|
||||
specs := strings.Split(cronjob.Spec, ",")
|
||||
specs := strings.Split(cronjob.Spec, "&&")
|
||||
var ids []string
|
||||
for _, spec := range specs {
|
||||
cronjob.Spec = spec
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ func InitAgentDB() {
|
|||
migrations.InitRecordStatus,
|
||||
migrations.AddShowNameForQuickJump,
|
||||
migrations.AddTimeoutForClam,
|
||||
migrations.UpdataCronjobSpec,
|
||||
})
|
||||
if err := m.Migrate(); err != nil {
|
||||
global.LOG.Error(err)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"os"
|
||||
"os/user"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/1Panel-dev/1Panel/agent/app/dto"
|
||||
|
|
@ -596,3 +597,23 @@ var AddTimeoutForClam = &gormigrate.Migration{
|
|||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var UpdataCronjobSpec = &gormigrate.Migration{
|
||||
ID: "20250925-update-cronjob-spec",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
var cronjobs []model.Cronjob
|
||||
if err := tx.Where("1 == 1").Find(&cronjobs).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
for _, item := range cronjobs {
|
||||
if !strings.Contains(item.Spec, ",") {
|
||||
continue
|
||||
}
|
||||
if err := tx.Model(&model.Cronjob{}).Where("id = ?", item.ID).Updates(
|
||||
map[string]interface{}{"spec": strings.ReplaceAll(item.Spec, ",", "&&")}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,19 +104,19 @@
|
|||
</el-table-column>
|
||||
<el-table-column :label="$t('cronjob.cronSpec')" show-overflow-tooltip :min-width="120">
|
||||
<template #default="{ row }">
|
||||
<div v-for="(item, index) of row.spec.split(',')" :key="index">
|
||||
<div v-for="(item, index) of row.spec.split('&&')" :key="index">
|
||||
<div v-if="row.expand || (!row.expand && index < 3)">
|
||||
<span>
|
||||
{{ row.specCustom ? item : transSpecToStr(item) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!row.expand && row.spec.split(',').length > 3">
|
||||
<div v-if="!row.expand && row.spec.split('&&').length > 3">
|
||||
<el-button type="primary" link @click="row.expand = true">
|
||||
{{ $t('commons.button.expand') }}...
|
||||
</el-button>
|
||||
</div>
|
||||
<div v-if="row.expand && row.spec.split(',').length > 3">
|
||||
<div v-if="row.expand && row.spec.split('&&').length > 3">
|
||||
<el-button type="primary" link @click="row.expand = false">
|
||||
{{ $t('commons.button.collapse') }}
|
||||
</el-button>
|
||||
|
|
|
|||
|
|
@ -869,13 +869,13 @@ const search = async () => {
|
|||
form.specs = res.data.specs || [];
|
||||
if (!form.specCustom && form.spec) {
|
||||
let objs = [];
|
||||
for (const item of res.data.spec.split(',')) {
|
||||
for (const item of res.data.spec.split('&&')) {
|
||||
objs.push(transSpecToObj(item));
|
||||
}
|
||||
form.specObjs = objs || [];
|
||||
}
|
||||
if (form.specCustom && form.spec) {
|
||||
form.specs = form.spec.split(',') || [];
|
||||
form.specs = form.spec.split('&&') || [];
|
||||
}
|
||||
|
||||
form.script = res.data.script;
|
||||
|
|
@ -1417,7 +1417,7 @@ const onSubmit = async (formEl: FormInstance | undefined) => {
|
|||
form.sourceDir = files.join(',');
|
||||
}
|
||||
form.sourceAccountIDs = form.sourceAccountItems.join(',');
|
||||
form.spec = specs.join(',');
|
||||
form.spec = specs.join('&&');
|
||||
if (!formEl) return;
|
||||
formEl.validate(async (valid) => {
|
||||
if (!valid) return;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue