Skip to content

Commit

Permalink
update job
Browse files Browse the repository at this point in the history
  • Loading branch information
orvice committed Oct 23, 2024
1 parent 46c75dc commit 2c8faa1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 215 deletions.
33 changes: 17 additions & 16 deletions cmd/ddns/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ package main

import (
"context"
"fmt"
"log/slog"
"os"
"strings"
"time"

"github.com/libdns/libdns"
"github.com/weeon/log"
"github.com/weeon/utils/task"

"github.com/orvice/ddns/dns"
"github.com/orvice/ddns/internal/config"
Expand All @@ -25,6 +22,7 @@ var (
)

func Init() error {
logger := slog.Default()
var err error
config.GetConfigFromEnv()
ipGetter = ip.NewIfconfigCo()
Expand All @@ -33,7 +31,7 @@ func Init() error {

notifier, err := notify.NewTelegramNotifier(config.TelegramToken, config.TelegramChatID)
if err != nil {
log.Errorf("notify init error %v", err)
logger.Error("notify init error", "error", err)
} else {
notify.AddNotifier(notifier)
}
Expand All @@ -47,25 +45,28 @@ func Init() error {
}

func main() {
var err error
log.FastInitFileLogger()
err = Init()
logger := slog.Default()
err := Init()
if err != nil {
fmt.Println(err)
logger.Error("init error", "error", err)
os.Exit(0)
}

ctx := context.Background()

task.NewTaskAndRun("updateUpdate", time.Minute*3, func() error {
err := updateIP(ctx)
if err != nil {
slog.Error("update ip error", "error", err.Error())
os.Exit(1)
for {
select {
case <-ctx.Done():
return
default:
err := updateIP(ctx)
if err != nil {
logger.Error("update ip error", "error", err.Error())
os.Exit(1)
}
time.Sleep(time.Minute * 3)
}
return err
}, task.SetTaskLogger(log.GetDefault()))
select {}
}
}

func updateIP(ctx context.Context) error {
Expand Down
14 changes: 0 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,12 @@ require (
github.com/libdns/cloudflare v0.1.1
github.com/libdns/libdns v0.2.2
github.com/orvice/utils v0.0.0-20180715141935-5b71615d9c36
github.com/weeon/log v0.0.0-20210217051817-63fe9a730962
github.com/weeon/utils v0.0.0-20190524044050-159b91233ff4
github.com/weppos/publicsuffix-go v0.4.0
)

require (
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/go-redis/redis/v8 v8.5.0 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/weeon/contract v0.0.0-20190520152601-a4ee53bdb563 // indirect
go.opentelemetry.io/otel v0.16.0 // indirect
go.uber.org/atomic v1.6.0 // indirect
go.uber.org/multierr v1.5.0 // indirect
go.uber.org/zap v1.15.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/text v0.13.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

go 1.23
Loading

0 comments on commit 2c8faa1

Please sign in to comment.