fix: env binding in oneshot and less output from dummy
This commit is contained in:
parent
b589fb8f0c
commit
2eae19f64c
@ -7,11 +7,10 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
for i := 0; i < 10; i++ {
|
||||
log.Println("using log.Println")
|
||||
fmt.Println("using fmt.Println")
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
}
|
||||
log.Println("using log.Println")
|
||||
fmt.Println("using fmt.Println")
|
||||
|
||||
time.Sleep(time.Second * 5)
|
||||
|
||||
log.Println("log: finishing up")
|
||||
fmt.Println("fmt: finishing up")
|
||||
|
||||
@ -22,7 +22,9 @@ const (
|
||||
|
||||
func main() {
|
||||
viper.SetEnvPrefix(EnvPrefix)
|
||||
viper.BindEnv(EnvDummyPath, EnvLog, EnvLogMessage)
|
||||
viper.BindEnv(EnvDummyPath)
|
||||
viper.BindEnv(EnvLog)
|
||||
viper.BindEnv(EnvLogMessage)
|
||||
viper.SetDefault(EnvDummyPath, DummyPath)
|
||||
viper.SetDefault(EnvLogMessage, EnvDefaultLogMessage)
|
||||
|
||||
@ -30,6 +32,7 @@ func main() {
|
||||
|
||||
logPath := viper.GetString(EnvLog)
|
||||
logMessage := viper.GetString(EnvLogMessage)
|
||||
log.Println("log path:", logPath)
|
||||
if logPath != "" {
|
||||
var (
|
||||
err error
|
||||
|
||||
@ -126,23 +126,25 @@ func (c *Cron) Command() string {
|
||||
}
|
||||
|
||||
func (c *Cron) TimeToRun(now time.Time) bool {
|
||||
if !c.hasRun {
|
||||
c.lastRun = now
|
||||
c.hasRun = true
|
||||
return true
|
||||
}
|
||||
|
||||
if now.Sub(c.lastRun) <= time.Minute && now.Minute() == c.lastRun.Minute() {
|
||||
return false
|
||||
}
|
||||
|
||||
if c.minute.Match(uint8(now.Minute())) &&
|
||||
c.hour.Match(uint8(now.Hour())) &&
|
||||
c.dom.Match(uint8(now.Day())) &&
|
||||
c.month.Match(uint8(now.Month())) &&
|
||||
c.dow.Match(uint8(now.Weekday())) {
|
||||
c.lastRun = now
|
||||
return true
|
||||
|
||||
if c.hasRun {
|
||||
if now.Sub(c.lastRun) <= time.Minute && now.Minute() == c.lastRun.Minute() {
|
||||
return false
|
||||
} else {
|
||||
c.lastRun = now
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
|
||||
c.lastRun = now
|
||||
c.hasRun = true
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
@ -3,4 +3,7 @@
|
||||
export WINGMATE_DUMMY_PATH=/usr/local/bin/wmdummy
|
||||
export WINGMATE_LOG=/var/log/cron1.log
|
||||
export WINGMATE_LOG_MESSAGE="cron executed in minute 5,10,15,20,25,30,35,40,45,50,55"
|
||||
|
||||
echo "I'm runnig with dummy=$WINGMATE_DUMMY_PATH, log=$WINGMATE_LOG and mesage=$WINGMATE_LOG_MESSAGE" >> /var/log/debug-cron.log
|
||||
|
||||
exec /usr/local/bin/wmoneshot
|
||||
Loading…
x
Reference in New Issue
Block a user