mirror of
https://github.com/MedzikUser/go-pingbot
synced 2024-08-14 23:57:07 +00:00
feat(config): Add Stop After Ping
This commit is contained in:
parent
107e9d3bd8
commit
7ef99d82c6
5 changed files with 74 additions and 34 deletions
|
@ -11,7 +11,7 @@ import (
|
|||
|
||||
var cacheRetry int
|
||||
|
||||
func ping() {
|
||||
func ping() int {
|
||||
if cacheRetry >= config.Toml.Backend.Cache {
|
||||
cache(0)
|
||||
cacheRetry = 0
|
||||
|
@ -21,6 +21,8 @@ func ping() {
|
|||
for _, url := range cacheURL {
|
||||
go loop(url)
|
||||
}
|
||||
|
||||
return len(cacheURL)
|
||||
}
|
||||
|
||||
func loop(url string) {
|
||||
|
|
14
backend/stop_after_ping.go
Normal file
14
backend/stop_after_ping.go
Normal file
|
@ -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]
|
||||
enabled=true # Enable Website
|
||||
port=8080 # Port to listen
|
||||
enabled=true # Enable Website
|
||||
port=8080 # Port to listen
|
||||
|
||||
[backend]
|
||||
enabled=true # Enable Backend
|
||||
ping=3 # Ping every three minutes
|
||||
cache=5 # Get urls from db every five url pings
|
||||
enabled=true # Enable Backend
|
||||
ping=3 # Ping every three minutes
|
||||
cache=5 # Get urls from db every five url pings
|
||||
|
||||
[autoupdate]
|
||||
enabled=true # Enable Auto Updater
|
||||
check=2 # Check every two minutes
|
||||
enabled=true # Enable Auto Updater
|
||||
check=2 # Check every two minutes
|
||||
|
||||
[cluster]
|
||||
id=1 # Cluster ID
|
||||
node=1 # Node ID
|
||||
id=1 # Cluster ID
|
||||
node=1 # Node ID
|
||||
|
||||
[mongodb]
|
||||
database="PingBot" # MongoDB Database Name
|
||||
collection="URL" # MongoDB Collection Name
|
||||
database="PingBot" # MongoDB Database Name
|
||||
collection="URL" # MongoDB Collection Name
|
||||
|
||||
[options]
|
||||
stop_after_ping=false # Stop after all pings
|
||||
|
|
|
@ -16,6 +16,7 @@ type tomlConfig struct {
|
|||
AutoUpdate autoUpdateConfig
|
||||
Cluster clusterConfig
|
||||
MongoDB mongoDBConfig
|
||||
Options optionsConfig
|
||||
}
|
||||
|
||||
type httpConfig struct {
|
||||
|
@ -44,6 +45,10 @@ type mongoDBConfig struct {
|
|||
Collection string
|
||||
}
|
||||
|
||||
type optionsConfig struct {
|
||||
Stop_After_Ping bool
|
||||
}
|
||||
|
||||
var Toml tomlConfig
|
||||
|
||||
func init() {
|
||||
|
|
60
main.go
60
main.go
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -22,6 +23,43 @@ func main() {
|
|||
|
||||
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 {
|
||||
wg.Add(1)
|
||||
go website.Server()
|
||||
|
@ -36,28 +74,6 @@ func main() {
|
|||
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()
|
||||
|
||||
wg.Wait()
|
||||
|
|
Loading…
Reference in a new issue