-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NextRunTime as schedule parameter to monitors and ping
- Loading branch information
Showing
6 changed files
with
100 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package cmd | ||
|
||
func GetNextRunFromMonitorKey(key string) string { | ||
return "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/capnspacehook/taskmaster" | ||
) | ||
|
||
// GetNextRunFromMonitorKey returns the NextRunTime timestamp from Windows | ||
// Task Scheduler. Since each `cronitor ping` call is run independently, | ||
// this call can't be memoized, regardless of how expensive it is. | ||
func GetNextRunFromMonitorKey(key string) string { | ||
taskService, err := taskmaster.Connect() | ||
if err != nil { | ||
log(fmt.Sprintf("err: %v", err)) | ||
return "" | ||
} | ||
defer taskService.Disconnect() | ||
collection, err := taskService.GetRegisteredTasks() | ||
if err != nil { | ||
log(fmt.Sprintf("err: %v", err)) | ||
return "" | ||
} | ||
defer collection.Release() | ||
|
||
for _, task := range collection { | ||
t := NewWrappedWindowsTask(task) | ||
|
||
if t.WindowsKey() == key { | ||
return t.GetNextRunTimeString() | ||
} | ||
} | ||
|
||
return "" | ||
} |