Compare commits
No commits in common. "0b5b26d5b0fa34fbfa3b2d515ca2a944ac011cf6" and "050e1894428eec9ac4dc536bc2695ab07069ffbd" have entirely different histories.
0b5b26d5b0
...
050e189442
@ -1,14 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"weatherstation/internal/server"
|
||||
)
|
||||
|
||||
func main() {
|
||||
server.SetupLogger()
|
||||
|
||||
if err := server.StartGinServer(); err != nil {
|
||||
log.Fatalf("service-api failed: %v", err)
|
||||
}
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"weatherstation/internal/server"
|
||||
"weatherstation/internal/tools"
|
||||
)
|
||||
|
||||
func main() {
|
||||
server.SetupLogger()
|
||||
|
||||
// If CAIYUN_TOKEN is provided, enable wind override automatically.
|
||||
opts := tools.ExporterOptions{}
|
||||
if token := os.Getenv("CAIYUN_TOKEN"); token != "" {
|
||||
opts.OverrideWindWithCaiyun = true
|
||||
opts.CaiyunToken = token
|
||||
log.Printf("[service-exporter] wind override enabled via CAIYUN_TOKEN")
|
||||
}
|
||||
|
||||
exp := tools.NewExporterWithOptions(opts)
|
||||
|
||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer stop()
|
||||
|
||||
if err := exp.Start(ctx); err != nil && !errors.Is(err, context.Canceled) {
|
||||
log.Fatalf("service-exporter failed: %v", err)
|
||||
}
|
||||
}
|
||||
@ -1,65 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
"weatherstation/internal/config"
|
||||
"weatherstation/internal/forecast"
|
||||
"weatherstation/internal/server"
|
||||
)
|
||||
|
||||
func hourlyLoop(ctx context.Context, fn func() error, name string) {
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
default:
|
||||
}
|
||||
now := time.Now()
|
||||
next := now.Truncate(time.Hour).Add(time.Hour)
|
||||
t := time.NewTimer(time.Until(next))
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
t.Stop()
|
||||
return
|
||||
case <-t.C:
|
||||
}
|
||||
if err := fn(); err != nil {
|
||||
log.Printf("[%s] scheduled run failed: %v", name, err)
|
||||
} else {
|
||||
log.Printf("[%s] scheduled run completed", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
server.SetupLogger()
|
||||
|
||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer stop()
|
||||
|
||||
// Open-Meteo hourly fetch
|
||||
go hourlyLoop(ctx, func() error { return forecast.RunOpenMeteoFetch(context.Background()) }, "open-meteo")
|
||||
|
||||
// Caiyun hourly fetch (if token configured)
|
||||
token := os.Getenv("CAIYUN_TOKEN")
|
||||
if token == "" {
|
||||
token = config.GetConfig().Forecast.CaiyunToken
|
||||
}
|
||||
if token == "" {
|
||||
log.Printf("[caiyun] token not set; caiyun scheduler disabled")
|
||||
} else {
|
||||
t := token
|
||||
go hourlyLoop(ctx, func() error { return forecast.RunCaiyunFetch(context.Background(), t) }, "caiyun")
|
||||
}
|
||||
|
||||
// CMA hourly fetch
|
||||
// go hourlyLoop(ctx, func() error { return forecast.RunCMAFetch(context.Background()) }, "cma")
|
||||
|
||||
<-ctx.Done()
|
||||
log.Println("service-forecast shutting down")
|
||||
}
|
||||
@ -1,50 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
"weatherstation/internal/fusion"
|
||||
"weatherstation/internal/server"
|
||||
)
|
||||
|
||||
func main() {
|
||||
server.SetupLogger()
|
||||
|
||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer stop()
|
||||
|
||||
go func() {
|
||||
for {
|
||||
if ctx.Err() != nil {
|
||||
return
|
||||
}
|
||||
now := time.Now()
|
||||
next := now.Truncate(time.Hour).Add(time.Hour).Add(5 * time.Minute)
|
||||
sleep := time.Until(next)
|
||||
if sleep < 0 {
|
||||
sleep = 0
|
||||
}
|
||||
t := time.NewTimer(sleep)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
t.Stop()
|
||||
return
|
||||
case <-t.C:
|
||||
}
|
||||
|
||||
issued := next.Truncate(time.Hour)
|
||||
if err := fusion.RunForIssued(context.Background(), issued); err != nil {
|
||||
log.Printf("[service-fusion] run failed: %v", err)
|
||||
} else {
|
||||
log.Printf("[service-fusion] completed issued=%s", issued.Format("2006-01-02 15:04:05"))
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
<-ctx.Done()
|
||||
log.Println("service-fusion shutting down")
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"weatherstation/internal/radar"
|
||||
"weatherstation/internal/server"
|
||||
)
|
||||
|
||||
func main() {
|
||||
server.SetupLogger()
|
||||
|
||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer stop()
|
||||
|
||||
// Start radar scheduler with defaults (StoreToDB=true; tile defaults read inside package)
|
||||
if err := radar.Start(ctx, radar.Options{StoreToDB: true}); err != nil {
|
||||
log.Fatalf("service-radar start error: %v", err)
|
||||
}
|
||||
|
||||
// Keep process alive until signal
|
||||
<-ctx.Done()
|
||||
log.Println("service-radar shutting down")
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"weatherstation/internal/server"
|
||||
)
|
||||
|
||||
func main() {
|
||||
server.SetupLogger()
|
||||
|
||||
if err := server.StartUDPServer(); err != nil {
|
||||
log.Fatalf("service-udp failed: %v", err)
|
||||
}
|
||||
}
|
||||
@ -15,6 +15,8 @@ import (
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
"weatherstation/internal/config"
|
||||
"weatherstation/internal/forecast"
|
||||
"weatherstation/internal/fusion"
|
||||
"weatherstation/internal/tools"
|
||||
"weatherstation/model"
|
||||
)
|
||||
@ -144,10 +146,67 @@ func StartUDPServer() error {
|
||||
}
|
||||
}()
|
||||
|
||||
// 说明:原有的 open-meteo/彩云/CMA 定时抓取已移除,避免与独立的 service-forecast 重复调度。
|
||||
// 若需要启用预报抓取,请运行 `cmd/service-forecast` 服务。
|
||||
// 后台定时:每小时拉取open-meteo(全站)
|
||||
go func() {
|
||||
for {
|
||||
now := time.Now()
|
||||
next := now.Truncate(time.Hour).Add(time.Hour)
|
||||
time.Sleep(time.Until(next))
|
||||
if err := forecast.RunOpenMeteoFetch(context.Background()); err != nil {
|
||||
log.Printf("open-meteo 定时拉取失败: %v", err)
|
||||
} else {
|
||||
log.Printf("open-meteo 定时拉取完成")
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// 说明:融合任务已迁移至独立服务(service-fusion)。
|
||||
// 后台定时:每小时拉取彩云(全站)
|
||||
go func() {
|
||||
token := config.GetConfig().Forecast.CaiyunToken
|
||||
if token == "" {
|
||||
log.Printf("caiyun token 未配置,跳过彩云定时拉取(配置 forecast.caiyun_token 可启用)")
|
||||
return
|
||||
}
|
||||
for {
|
||||
now := time.Now()
|
||||
next := now.Truncate(time.Hour).Add(time.Hour)
|
||||
time.Sleep(time.Until(next))
|
||||
if err := forecast.RunCaiyunFetch(context.Background(), token); err != nil {
|
||||
log.Printf("caiyun 定时拉取失败: %v", err)
|
||||
} else {
|
||||
log.Printf("caiyun 定时拉取完成")
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// 后台定时:每小时拉取CMA(全站,共用一份数据,缺失填0)
|
||||
go func() {
|
||||
for {
|
||||
now := time.Now()
|
||||
next := now.Truncate(time.Hour).Add(time.Hour)
|
||||
time.Sleep(time.Until(next))
|
||||
if err := forecast.RunCMAFetch(context.Background()); err != nil {
|
||||
log.Printf("cma 定时拉取失败: %v", err)
|
||||
} else {
|
||||
log.Printf("cma 定时拉取完成")
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// 后台定时:每小时整点+5分 执行融合任务(全站),发布 imdroid_mix
|
||||
go func() {
|
||||
for {
|
||||
now := time.Now()
|
||||
next := now.Truncate(time.Hour).Add(time.Hour).Add(5 * time.Minute)
|
||||
time.Sleep(time.Until(next))
|
||||
issued := next.Truncate(time.Hour)
|
||||
if err := fusion.RunForIssued(context.Background(), issued); err != nil {
|
||||
log.Printf("fusion 定时执行失败: %v", err)
|
||||
} else {
|
||||
log.Printf("fusion 定时执行完成 issued=%s", issued.Format("2006-01-02 15:04:05"))
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
n, addr, err := conn.ReadFrom(buffer)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user