Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bc376ec

Browse files
fix: script-type scheduled task import/export issues (1Panel-dev#9713)
1 parent 40314e9 commit bc376ec

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

‎agent/app/service/cronjob.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package service
22

33
import (
4+
"context"
45
"encoding/json"
56
"fmt"
67
"os"
@@ -15,6 +16,7 @@ import (
1516
"github.com/1Panel-dev/1Panel/agent/buserr"
1617
"github.com/1Panel-dev/1Panel/agent/constant"
1718
"github.com/1Panel-dev/1Panel/agent/global"
19+
"github.com/1Panel-dev/1Panel/agent/utils/docker"
1820
"github.com/jinzhu/copier"
1921
"github.com/pkg/errors"
2022
"github.com/robfig/cron/v3"
@@ -159,6 +161,14 @@ func (u *CronjobService) Export(req dto.OperateByIDs) (string, error) {
159161
for _, db := range databases {
160162
item.DBNames = append(item.DBNames, dto.TransHelper{Name: db.Database, DetailName: db.Name})
161163
}
164+
case "shell":
165+
if cronjob.ScriptMode == "library" {
166+
script, err := scriptRepo.Get(repo.WithByID(cronjob.ScriptID))
167+
if err != nil {
168+
return "", err
169+
}
170+
item.ScriptName = script.Name
171+
}
162172
}
163173
item.SourceAccounts, item.DownloadAccount, _ = loadBackupNamesByID(cronjob.SourceAccountIDs, cronjob.DownloadAccountID)
164174
alertInfo, _ := alertRepo.Get(alertRepo.WithByType(cronjob.Type), alertRepo.WithByProject(strconv.Itoa(int(cronjob.ID))), repo.WithByStatus(constant.AlertEnable))
@@ -191,7 +201,6 @@ func (u *CronjobService) Import(req []dto.CronjobTrans) error {
191201
Spec: item.Spec,
192202
Executor: item.Executor,
193203
ScriptMode: item.ScriptMode,
194-
Script: item.Script,
195204
Command: item.Command,
196205
ContainerName: item.ContainerName,
197206
User: item.User,
@@ -265,6 +274,36 @@ func (u *CronjobService) Import(req []dto.CronjobTrans) error {
265274
}
266275
}
267276
cronjob.DBName = strings.Join(dbIDs, ",")
277+
case "shell":
278+
if len(item.ContainerName) != 0 {
279+
client, err := docker.NewDockerClient()
280+
if err != nil {
281+
hasNotFound = true
282+
continue
283+
}
284+
defer client.Close()
285+
if _, err := client.ContainerStats(context.Background(), item.ContainerName, false); err != nil {
286+
hasNotFound = true
287+
continue
288+
}
289+
}
290+
switch item.ScriptMode {
291+
case "library":
292+
library, _ := scriptRepo.Get(repo.WithByName(item.ScriptName))
293+
if library.ID == 0 {
294+
hasNotFound = true
295+
continue
296+
}
297+
cronjob.ScriptID = library.ID
298+
case "select":
299+
if _, err := os.Stat(item.Script); err != nil {
300+
hasNotFound = true
301+
continue
302+
}
303+
cronjob.Script = item.Script
304+
case "input":
305+
cronjob.Script = item.Script
306+
}
268307
}
269308
var acIDs []string
270309
for _, ac := range item.SourceAccounts {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /