Browse Source

final fixes

tags/version-1.0
Vladimir Smagin 1 year ago
parent
commit
c06f3d08b7
4 changed files with 11 additions and 8 deletions
  1. 2
    2
      config.go
  2. 0
    1
      configs/test1.yml
  3. 2
    3
      file_utils.go
  4. 7
    2
      gogocron.go

+ 2
- 2
config.go View File

@@ -9,10 +9,10 @@ func loadConfig() cronTasks {
var tasks cronTasks

configFiles := readConfigDirectory("configs")
log.Printf("Files found: %v", configFiles)
log.Printf("Configuration files found: %v", configFiles)
for _, configFile := range configFiles {
config := readConfigFile(configFile)
log.Printf("Parsed %#v", config)
//log.Printf("Parsed %#v", config)
tasks = append(tasks, config)
}
return tasks

+ 0
- 1
configs/test1.yml View File

@@ -1,7 +1,6 @@
---
name: "Print base64 of 20 random symbols"
runsecond: "*/5"
timeout: 4s
env:
- TESTVAR="test variable"
commands:

+ 2
- 3
file_utils.go View File

@@ -24,7 +24,7 @@ func readConfigDirectory(path string) []string {
}

for _, file := range files {
log.Println(file.Name())
//log.Println(file.Name())
res = append(res, path+"/"+file.Name())
}

@@ -52,14 +52,13 @@ func readConfigFile(path string) cronTask {

// run commands
func runCmd(ctx context.Context, env []string, cmdname string, params ...string) error {
log.Println("runCmd:", cmdname, params)
log.Println("Executing", cmdname, params)
cmd := exec.Command(cmdname, params...)

// set env variables
cmd.Env = append(cmd.Env, os.Environ()...)
cmd.Env = append(cmd.Env, env...)

log.Printf("runCmd: env %v", env)
// set stdout, stderr
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

+ 7
- 2
gogocron.go View File

@@ -74,8 +74,8 @@ func executeTasks(tasks cronTasks) {

// iterate tasks and run them in go routine
for _, task := range tasks {
log.Printf("\ttask: %#v", task.Name)
log.Printf("\t\tcommands: %#v", task.Commands)
log.Printf("task: %#v Timeout: %#v", task.Name, task.TimeOut)
log.Printf("commands: %#v", task.Commands)

if task.TimeOut != "" {
timeout, err := time.ParseDuration(task.TimeOut)
@@ -118,6 +118,11 @@ func executeTask(ctx context.Context, task cronTask) {
}

func main() {
log.Println(`GoGoCron welcomes you!
Now you can run cron tasks even every second.
Copyright by Vladimir Smagin, 2018 (http://blindage.org)
Version 1.0
Visit http://gogocron.blindage.org to read manual and updates`)
// Load config at startup
tasks := loadConfig()


Loading…
Cancel
Save