mirror of https://github.com/MedzikUser/go-pingbot
feat(config): Add Stop After Ping
This commit is contained in:
parent
107e9d3bd8
commit
7ef99d82c6
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
var cacheRetry int
|
var cacheRetry int
|
||||||
|
|
||||||
func ping() {
|
func ping() int {
|
||||||
if cacheRetry >= config.Toml.Backend.Cache {
|
if cacheRetry >= config.Toml.Backend.Cache {
|
||||||
cache(0)
|
cache(0)
|
||||||
cacheRetry = 0
|
cacheRetry = 0
|
||||||
|
@ -21,6 +21,8 @@ func ping() {
|
||||||
for _, url := range cacheURL {
|
for _, url := range cacheURL {
|
||||||
go loop(url)
|
go loop(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return len(cacheURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loop(url string) {
|
func loop(url string) {
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package backend
|
||||||
|
|
||||||
|
func StopAfterPing() int {
|
||||||
|
cache(0)
|
||||||
|
num := ping()
|
||||||
|
|
||||||
|
for {
|
||||||
|
if int64(num) == Status.Success+Status.Error {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return num
|
||||||
|
}
|
|
@ -1,20 +1,23 @@
|
||||||
[http]
|
[http]
|
||||||
enabled=true # Enable Website
|
enabled=true # Enable Website
|
||||||
port=8080 # Port to listen
|
port=8080 # Port to listen
|
||||||
|
|
||||||
[backend]
|
[backend]
|
||||||
enabled=true # Enable Backend
|
enabled=true # Enable Backend
|
||||||
ping=3 # Ping every three minutes
|
ping=3 # Ping every three minutes
|
||||||
cache=5 # Get urls from db every five url pings
|
cache=5 # Get urls from db every five url pings
|
||||||
|
|
||||||
[autoupdate]
|
[autoupdate]
|
||||||
enabled=true # Enable Auto Updater
|
enabled=true # Enable Auto Updater
|
||||||
check=2 # Check every two minutes
|
check=2 # Check every two minutes
|
||||||
|
|
||||||
[cluster]
|
[cluster]
|
||||||
id=1 # Cluster ID
|
id=1 # Cluster ID
|
||||||
node=1 # Node ID
|
node=1 # Node ID
|
||||||
|
|
||||||
[mongodb]
|
[mongodb]
|
||||||
database="PingBot" # MongoDB Database Name
|
database="PingBot" # MongoDB Database Name
|
||||||
collection="URL" # MongoDB Collection Name
|
collection="URL" # MongoDB Collection Name
|
||||||
|
|
||||||
|
[options]
|
||||||
|
stop_after_ping=false # Stop after all pings
|
||||||
|
|
|
@ -16,6 +16,7 @@ type tomlConfig struct {
|
||||||
AutoUpdate autoUpdateConfig
|
AutoUpdate autoUpdateConfig
|
||||||
Cluster clusterConfig
|
Cluster clusterConfig
|
||||||
MongoDB mongoDBConfig
|
MongoDB mongoDBConfig
|
||||||
|
Options optionsConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
type httpConfig struct {
|
type httpConfig struct {
|
||||||
|
@ -44,6 +45,10 @@ type mongoDBConfig struct {
|
||||||
Collection string
|
Collection string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type optionsConfig struct {
|
||||||
|
Stop_After_Ping bool
|
||||||
|
}
|
||||||
|
|
||||||
var Toml tomlConfig
|
var Toml tomlConfig
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
60
main.go
60
main.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -22,6 +23,43 @@ func main() {
|
||||||
|
|
||||||
mongo.Connect()
|
mongo.Connect()
|
||||||
|
|
||||||
|
if config.Toml.AutoUpdate.Enabled {
|
||||||
|
wg.Add(1)
|
||||||
|
|
||||||
|
client := updater.Client{
|
||||||
|
GitHub: config.GH_Repo,
|
||||||
|
GitHubToken: config.GH_Token,
|
||||||
|
Version: config.Version,
|
||||||
|
Binary: "pingbot.out",
|
||||||
|
CheckEvery: config.Toml.AutoUpdate.Check * time.Minute,
|
||||||
|
AfterUpdate: func() {
|
||||||
|
log.Info("Updated!")
|
||||||
|
|
||||||
|
if !config.Toml.Options.Stop_After_Ping {
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Major: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
go client.AutoUpdater()
|
||||||
|
} else {
|
||||||
|
log.Warn("Auto Update -> Disabled")
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Toml.Options.Stop_After_Ping {
|
||||||
|
dbNum := backend.StopAfterPing()
|
||||||
|
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
|
log.Info("DB Size -> ", dbNum)
|
||||||
|
log.Info("Pinged -> ", backend.Status.Success+backend.Status.Error)
|
||||||
|
log.Info("Success -> ", backend.Status.Success)
|
||||||
|
log.Info("Error -> ", backend.Status.Error)
|
||||||
|
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
if config.Toml.HTTP.Enabled {
|
if config.Toml.HTTP.Enabled {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go website.Server()
|
go website.Server()
|
||||||
|
@ -36,28 +74,6 @@ func main() {
|
||||||
log.Warn("Backend -> Disabled")
|
log.Warn("Backend -> Disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Toml.AutoUpdate.Enabled {
|
|
||||||
wg.Add(1)
|
|
||||||
|
|
||||||
client := updater.Client{
|
|
||||||
GitHub: config.GH_Repo,
|
|
||||||
GitHubToken: config.GH_Token,
|
|
||||||
Version: config.Version,
|
|
||||||
Binary: "pingbot.out",
|
|
||||||
CheckEvery: config.Toml.AutoUpdate.Check * time.Minute,
|
|
||||||
AfterUpdate: func() {
|
|
||||||
log.Info("Updated!")
|
|
||||||
|
|
||||||
os.Exit(1)
|
|
||||||
},
|
|
||||||
Major: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
go client.AutoUpdater()
|
|
||||||
} else {
|
|
||||||
log.Warn("Auto Update -> Disabled")
|
|
||||||
}
|
|
||||||
|
|
||||||
config.StartTime = time.Now()
|
config.StartTime = time.Now()
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
Loading…
Reference in New Issue