fix: Fix the issue where cronjob expressions do not support commas (#10493)

Refs #9748
This commit is contained in:
ssongliu 2025-09-26 15:12:13 +08:00 committed by GitHub
parent 8f0c84c2a5
commit c4b3efeb9d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 29 additions and 7 deletions

View file

@ -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

View file

@ -44,6 +44,7 @@ func InitAgentDB() {
migrations.InitRecordStatus,
migrations.AddShowNameForQuickJump,
migrations.AddTimeoutForClam,
migrations.UpdataCronjobSpec,
})
if err := m.Migrate(); err != nil {
global.LOG.Error(err)

View file

@ -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
},
}

View file

@ -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>

View file

@ -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;