uptime
This commit is contained in:
3
.env
3
.env
@ -1 +1,2 @@
|
|||||||
POSTGRESQL_DSN="host=localhost port=5432 user=postgres password=123321Aa dbname=platiparser sslmode=disable"
|
POSTGRESQL_DSN="host=localhost port=5432 user=postgres password=123321Aa dbname=platiparser sslmode=disable"
|
||||||
|
UPTIMEKUMA_URL="https://uptime.home.4it.me/api/push/lqWN0TxOMn"
|
@ -10,6 +10,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.home.4it.me/dilap54/platiparser/gorm"
|
"gitea.home.4it.me/dilap54/platiparser/gorm"
|
||||||
|
"gitea.home.4it.me/dilap54/platiparser/healthbeat"
|
||||||
"gitea.home.4it.me/dilap54/platiparser/plati"
|
"gitea.home.4it.me/dilap54/platiparser/plati"
|
||||||
"gitea.home.4it.me/dilap54/platiparser/proxies"
|
"gitea.home.4it.me/dilap54/platiparser/proxies"
|
||||||
uuid "github.com/satori/go.uuid"
|
uuid "github.com/satori/go.uuid"
|
||||||
@ -24,6 +25,8 @@ func init() {
|
|||||||
var platiCommand = &cli.Command{
|
var platiCommand = &cli.Command{
|
||||||
Name: "plati",
|
Name: "plati",
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
|
timeStart := time.Now()
|
||||||
|
|
||||||
categories := openCategories("./categories.json").Content
|
categories := openCategories("./categories.json").Content
|
||||||
categories = filterBySubstring("Gift", categories)
|
categories = filterBySubstring("Gift", categories)
|
||||||
|
|
||||||
@ -34,6 +37,8 @@ var platiCommand = &cli.Command{
|
|||||||
|
|
||||||
// printNames(categories)
|
// printNames(categories)
|
||||||
|
|
||||||
|
beatUrl := os.Getenv("UPTIMEKUMA_URL")
|
||||||
|
|
||||||
wg, _ := errgroup.WithContext(ctx)
|
wg, _ := errgroup.WithContext(ctx)
|
||||||
wg.SetLimit(10)
|
wg.SetLimit(10)
|
||||||
|
|
||||||
@ -62,7 +67,14 @@ var platiCommand = &cli.Command{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return wg.Wait()
|
if err := wg.Wait(); err != nil {
|
||||||
|
healthbeat.Beat(beatUrl, "down", err.Error(), int(time.Since(timeStart).Milliseconds()))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
healthbeat.Beat(beatUrl, "up", "OK", int(time.Since(timeStart).Milliseconds()))
|
||||||
|
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
healthbeat/beat.go
Normal file
15
healthbeat/beat.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package healthbeat
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Beat(url, status, msg string, ping int) {
|
||||||
|
resp, err := http.Get(fmt.Sprintf("%s?status=%s&msg=%s&ping=%d", url, status, msg, ping))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("beat: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
}
|
Reference in New Issue
Block a user