fix: Fix import issues of shell cronjob (#9726)

This commit is contained in:
ssongliu 2025-07-29 12:09:49 +08:00 committed by GitHub
parent bc376ec495
commit ed3e738fff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -276,15 +276,16 @@ func (u *CronjobService) Import(req []dto.CronjobTrans) error {
cronjob.DBName = strings.Join(dbIDs, ",") cronjob.DBName = strings.Join(dbIDs, ",")
case "shell": case "shell":
if len(item.ContainerName) != 0 { if len(item.ContainerName) != 0 {
cronjob.Script = item.Script
client, err := docker.NewDockerClient() client, err := docker.NewDockerClient()
if err != nil { if err != nil {
hasNotFound = true hasNotFound = true
continue break
} }
defer client.Close() defer client.Close()
if _, err := client.ContainerStats(context.Background(), item.ContainerName, false); err != nil { if _, err := client.ContainerStats(context.Background(), item.ContainerName, false); err != nil {
hasNotFound = true hasNotFound = true
continue break
} }
} }
switch item.ScriptMode { switch item.ScriptMode {
@ -292,13 +293,13 @@ func (u *CronjobService) Import(req []dto.CronjobTrans) error {
library, _ := scriptRepo.Get(repo.WithByName(item.ScriptName)) library, _ := scriptRepo.Get(repo.WithByName(item.ScriptName))
if library.ID == 0 { if library.ID == 0 {
hasNotFound = true hasNotFound = true
continue break
} }
cronjob.ScriptID = library.ID cronjob.ScriptID = library.ID
case "select": case "select":
if _, err := os.Stat(item.Script); err != nil { if _, err := os.Stat(item.Script); err != nil {
hasNotFound = true hasNotFound = true
continue break
} }
cronjob.Script = item.Script cronjob.Script = item.Script
case "input": case "input":