Compare commits
No commits in common. "8b33722b1c13e438cb5a3d1b717fb9256e5be999" and "a1f5ce5d2bf3cde26a2e063c20cd867e9fc475c1" have entirely different histories.
8b33722b1c
...
a1f5ce5d2b
|
@ -3,7 +3,7 @@ packages:
|
||||||
- go
|
- go
|
||||||
- python3-dev
|
- python3-dev
|
||||||
- tar
|
- tar
|
||||||
- zstd
|
- xz
|
||||||
tasks:
|
tasks:
|
||||||
- go-get: |
|
- go-get: |
|
||||||
cd hswro-alarm-bot
|
cd hswro-alarm-bot
|
||||||
|
@ -23,6 +23,6 @@ tasks:
|
||||||
env GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o alarm_bot.x86-64
|
env GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o alarm_bot.x86-64
|
||||||
- compress: |
|
- compress: |
|
||||||
cd hswro-alarm-bot
|
cd hswro-alarm-bot
|
||||||
tar --zstd -cvf alarm_bot.tar.zstd alarm_bot.x86-64
|
tar cJvf alarm_bot.tar.xz alarm_bot.x86-64
|
||||||
artifacts:
|
artifacts:
|
||||||
- hswro-alarm-bot/alarm_bot.tar.zstd
|
- hswro-alarm-bot/alarm_bot.tar.xz
|
||||||
|
|
|
@ -34,7 +34,6 @@ type AppConfig struct {
|
||||||
ArmCallbackUrls []string `yaml:"arm-callback-urls"`
|
ArmCallbackUrls []string `yaml:"arm-callback-urls"`
|
||||||
DisarmCallbackUrls []string `yaml:"disarm-callback-urls"`
|
DisarmCallbackUrls []string `yaml:"disarm-callback-urls"`
|
||||||
AlarmCallbackUrls []string `yaml:"alarm-callback-urls"`
|
AlarmCallbackUrls []string `yaml:"alarm-callback-urls"`
|
||||||
WriteMemoryProfile bool `yaml:"write-memory-profile"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *SatelChangeType) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
func (m *SatelChangeType) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
|
@ -94,7 +93,6 @@ func getCmdLineParams(config *AppConfig, logger *log.Logger) {
|
||||||
allowedTypesRaw := flag.String("allowed-types", "", "Satel change types that are allowed. All other types will be discarded. By default all are allowed. Use \",\" to specify multiple types.")
|
allowedTypesRaw := flag.String("allowed-types", "", "Satel change types that are allowed. All other types will be discarded. By default all are allowed. Use \",\" to specify multiple types.")
|
||||||
allowedIndexesRaw := flag.String("allowed-indexes", "", "Satel indexes (zones?) that are allowed. All other indexes will be discarded. By default all are allowed. Use \",\" to specify multiple indexes.")
|
allowedIndexesRaw := flag.String("allowed-indexes", "", "Satel indexes (zones?) that are allowed. All other indexes will be discarded. By default all are allowed. Use \",\" to specify multiple indexes.")
|
||||||
satelPoolInterval := flag.Duration("pool-interval", 5*time.Second, "How often should the SATEL device be pooled for changes? Default: 5 seconds.")
|
satelPoolInterval := flag.Duration("pool-interval", 5*time.Second, "How often should the SATEL device be pooled for changes? Default: 5 seconds.")
|
||||||
writeMemoryProfile := flag.Bool("write-memory-profile", false, "Whether application should dump its memory profile every 24 hours. Default: false")
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if len(*satelApiAddr) == 0 || len(*satelApiPort) == 0 || len(*chatIdRaw) == 0 {
|
if len(*satelApiAddr) == 0 || len(*satelApiPort) == 0 || len(*chatIdRaw) == 0 {
|
||||||
|
@ -133,9 +131,6 @@ func getCmdLineParams(config *AppConfig, logger *log.Logger) {
|
||||||
}
|
}
|
||||||
allowedIndexes = append(allowedIndexes, int(allowedIndex))
|
allowedIndexes = append(allowedIndexes, int(allowedIndex))
|
||||||
}
|
}
|
||||||
if writeMemoryProfile != nil {
|
|
||||||
config.WriteMemoryProfile = *writeMemoryProfile
|
|
||||||
}
|
|
||||||
|
|
||||||
satelAddr := fmt.Sprintf("%s:%s", *satelApiAddr, *satelApiPort)
|
satelAddr := fmt.Sprintf("%s:%s", *satelApiAddr, *satelApiPort)
|
||||||
|
|
||||||
|
@ -151,7 +146,6 @@ func MakeConfig(logger *log.Logger) AppConfig {
|
||||||
config.ArmCallbackUrls = []string{}
|
config.ArmCallbackUrls = []string{}
|
||||||
config.DisarmCallbackUrls = []string{}
|
config.DisarmCallbackUrls = []string{}
|
||||||
config.AlarmCallbackUrls = []string{}
|
config.AlarmCallbackUrls = []string{}
|
||||||
config.WriteMemoryProfile = false
|
|
||||||
|
|
||||||
if len(os.Getenv("NOTIFY_URL_ARM")) != 0 {
|
if len(os.Getenv("NOTIFY_URL_ARM")) != 0 {
|
||||||
config.ArmCallbackUrls = append(config.ArmCallbackUrls, os.Getenv("NOTIFY_URL_ARM"))
|
config.ArmCallbackUrls = append(config.ArmCallbackUrls, os.Getenv("NOTIFY_URL_ARM"))
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"runtime/pprof"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func dumpMemoryProfile(log *log.Logger) {
|
|
||||||
path := fmt.Sprintf("%s/hswro_alarm_bot_%s.mprof", os.Getenv("RUNTIME_DIRECTORY"), time.Now().Format(time.RFC3339))
|
|
||||||
f, err := os.Create(path)
|
|
||||||
if err != nil {
|
|
||||||
log.Print("Error dumping memory profile to file: ", err)
|
|
||||||
}
|
|
||||||
pprof.WriteHeapProfile(f)
|
|
||||||
f.Close()
|
|
||||||
log.Print("Dumped memory profile to: ", path)
|
|
||||||
}
|
|
||||||
|
|
||||||
func WriteMemoryProfilePeriodically(wg *sync.WaitGroup, log *log.Logger, close <-chan interface{}) {
|
|
||||||
go func() {
|
|
||||||
wg.Add(1)
|
|
||||||
defer wg.Done()
|
|
||||||
memoryProfileTicker := time.NewTicker(24 * time.Hour)
|
|
||||||
defer memoryProfileTicker.Stop()
|
|
||||||
select {
|
|
||||||
case <-memoryProfileTicker.C:
|
|
||||||
dumpMemoryProfile(log)
|
|
||||||
case <-close:
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
3
main.go
3
main.go
|
@ -88,10 +88,7 @@ func main() {
|
||||||
tgEvents <- GenericMessage{e.BasicEvents}
|
tgEvents <- GenericMessage{e.BasicEvents}
|
||||||
}
|
}
|
||||||
|
|
||||||
closeDebugTools := make(chan interface{})
|
|
||||||
WriteMemoryProfilePeriodically(&wg, log.New(os.Stderr, "DebugTools", log.Lmicroseconds), closeDebugTools)
|
|
||||||
logger.Print("Closing...")
|
logger.Print("Closing...")
|
||||||
close(closeDebugTools)
|
|
||||||
close(tgEvents)
|
close(tgEvents)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
if cleanShutdown.Load() {
|
if cleanShutdown.Load() {
|
||||||
|
|
Loading…
Reference in New Issue