Skip to content

Commit

Permalink
regbyusehome
Browse files Browse the repository at this point in the history
  • Loading branch information
eatmeatball committed Jun 30, 2024
1 parent 6982fa1 commit 1e2d5fc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
32 changes: 32 additions & 0 deletions jobmanager/job_reg.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (
"errors"
"fmt"
"github.com/leancodebox/cock/cockSay"
"github.com/leancodebox/cock/resource"
"github.com/robfig/cron/v3"
"log/slog"
"os"
"os/exec"
"path"
"slices"
"sync"
"time"
Expand Down Expand Up @@ -154,6 +156,36 @@ func (itself *jobHandle) StopJob() {

var jobConfig JobConfig

func RegByUserConfig() error {
homeDir, err := os.UserHomeDir()
if err != nil {
fmt.Println("获取家目录失败:", err)
return err
}
fmt.Println("当前系统的家目录:", homeDir)
configDir := path.Join(homeDir, ".cockTaskConfig")
if _, err = os.Stat(configDir); os.IsNotExist(err) {
err = os.Mkdir(configDir, os.ModePerm)
if err != nil {
return err
}
}
jobConfigPath := path.Join(configDir, "jobConfig.json")
if _, err = os.Stat(jobConfigPath); os.IsNotExist(err) {
err = os.WriteFile(jobConfigPath, resource.GetJobConfigDefault(), 0644)
if err != nil {
fmt.Println("无法写入文件,错误:", err)
return err
}
}
fileData, err := os.ReadFile(jobConfigPath)
if err != nil {
return err
}
Reg(fileData)
return nil
}

func Reg(fileData []byte) {

err := json.Unmarshal(fileData, &jobConfig)
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ func main() {
return
}

//err = jobmanager.RegByUserConfig()
//if err != nil {
// fmt.Println(err)
// return
//}
jobmanager.Reg(fileData)
jobmanagerserver.ServeRun()
quit := make(chan os.Signal)
Expand Down

0 comments on commit 1e2d5fc

Please sign in to comment.