Browse Source

#4 filterTasksToExecute is not complete

tags/version-1.0
Vladimir Smagin 1 year ago
parent
commit
1e2aa382c1
2 changed files with 24 additions and 2 deletions
  1. 1
    0
      configs/test1.yml
  2. 23
    2
      gogocron.go

+ 1
- 0
configs/test1.yml View File

@@ -1,6 +1,7 @@
---
name: "Print base64 of 20 random symbols"
runsecond: "5,15,35,45"
runminute: "51"
timeout: 1
commands:
- "head -c 20 /dev/urandom |base64"

+ 23
- 2
gogocron.go View File

@@ -24,8 +24,29 @@ func filterTasksToExecute(tasks cronTasks) cronTasks {
now := time.Now()
var tasksToExecute cronTasks
for _, task := range tasks {
// calculate seconds
if isReadyToExec(task.RunSecond, now.Second()) {
taskIsForExecute := true

if task.RunSecond != "" && taskIsForExecute {
taskIsForExecute = isReadyToExec(task.RunSecond, now.Second())
}
if task.RunMinute != "" && taskIsForExecute {
taskIsForExecute = isReadyToExec(task.RunMinute, now.Minute())
}
if task.RunHour != "" && taskIsForExecute {
taskIsForExecute = isReadyToExec(task.RunHour, now.Hour())
}
if task.RunDom != "" && taskIsForExecute {
taskIsForExecute = isReadyToExec(task.RunDom, now.Day())
}
if task.RunMonth != "" && taskIsForExecute {
taskIsForExecute = isReadyToExec(task.RunMonth, int(now.Month()))
}

if task.RunDow != "" && taskIsForExecute {
taskIsForExecute = isReadyToExec(task.RunDow, int(now.Weekday()))
}

if taskIsForExecute {
tasksToExecute = append(tasksToExecute, task)
}
}

Loading…
Cancel
Save