BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr
Change log level to prod. Improved run_dev.sh. Added sent and relays data collection.
Jack7229b943c426
diff --git a/core/internal/service/collect/collect.go b/core/internal/service/collect/collect.gonew file mode 100644index 00000000..1fd61f38--- /dev/null+++ b/core/internal/service/collect/collect.go@@ -0,0 +1,60 @@+package collect++import (+ "billionmail-core/internal/service/public"+ "context"+ "github.com/gogf/gf/v2/frame/g"+ "time"+)++func Collect(ctx context.Context) {+ g.Log().Debug(ctx, "Collecting mail sent and relay counts")++ apiBase := "https://www.aapanel.com/api/panel/submit_feature_invoked"++ // Get last post time+ var lastPostTime int64+ _ = public.OptionsMgrInstance.GetOption(ctx, "last_post_time", &lastPostTime)++ // Get current time+ curTime := time.Now().Unix()++ if lastPostTime == 0 || curTime-lastPostTime > 24*60*60 {+ lastPostTime = curTime+ }++ defer func() {+ // Update last post time+ _ = public.OptionsMgrInstance.SetOption(ctx, "last_post_time", curTime)+ }()++ var cnt int++ // Get sent total count+ cnt, _ = g.DB().Model("mailstate_send_mails").Where("log_time > ?", lastPostTime).Count()++ resp, err := g.Client().ContentJson().Post(ctx, apiBase, g.Map{+ "feature": "bm.sent",+ "cnt": cnt,+ })++ if err != nil {+ g.Log().Warning(ctx, "Failed to post sent count: ", err)+ }++ g.Log().Debug(ctx, "sent count response: ", string(resp.ReadAll()))++ // Get relay count+ cnt, _ = g.DB().Model("bm_relay").Where("create_time > ?", lastPostTime).Count()++ resp, err = g.Client().ContentJson().Post(ctx, apiBase, g.Map{+ "feature": "bm.relays",+ "cnt": cnt,+ })++ if err != nil {+ g.Log().Warning(ctx, "Failed to post relay count: ", err)+ }++ g.Log().Debug(ctx, "relay count response: ", string(resp.ReadAll()))+}diff --git a/core/internal/service/timers/timers.go b/core/internal/service/timers/timers.goindex dfda2d99..88c59503 100644--- a/core/internal/service/timers/timers.go+++ b/core/internal/service/timers/timers.go@@ -2,6 +2,7 @@ package timersimport ("billionmail-core/internal/service/batch_mail"+ "billionmail-core/internal/service/collect""billionmail-core/internal/service/domains""billionmail-core/internal/service/mail_boxes""billionmail-core/internal/service/maillog_stat"@@ -74,6 +75,14 @@ func Start(ctx context.Context) (err error) {me.Start()})+ // Collect mail-sent total and mail-relay total+ gtimer.AddOnce(5*time.Second, func() {+ collect.Collect(ctx)+ })+ gtimer.Add(2*time.Hour, func() {+ collect.Collect(ctx)+ })+// ========== Mail task processing: one executor per task ==========gtimer.Add(5*time.Second, func() {batch_mail.ProcessEmailTasks(ctx)diff --git a/core/manifest/config/config.yaml b/core/manifest/config/config.yamlindex 0600e999..0a37f0b2 100644--- a/core/manifest/config/config.yaml+++ b/core/manifest/config/config.yaml@@ -56,7 +56,7 @@ logger:path: "logs/out" # Log file path. Default is empty, indicating that it is closed and only output to the terminalfile: "{Y-m-d}.log" # Log file format. Default is "{Y-m-d}.log"prefix: "" # Log content output prefix. Default is empty- level: "all" # Log output level+ level: "prod" # Log output leveltimeFormat: "2006-01-02T15:04:05" # Custom log output time format, using Golang standard time format configurationctxKeys: [] # Custom Context variable name, automatically print Context variables to the log. Default is emptyheader: true # Whether to print the header information of the log. Default is truediff --git a/core/run_dev.sh b/core/run_dev.shindex ef5ab67b..e833a9d3 100644--- a/core/run_dev.sh+++ b/core/run_dev.sh@@ -20,9 +20,36 @@ elseexit 1fi+echo "Copying the compiled binary from p-g-alpine to billionmail-core-billionmail-1..."+# Copy the compiled binary to the billionmail-core-billionmail-1 containerdocker cp $BINARY billionmail-core-billionmail-1:/opt/billionmail/core/billionmail++echo "Removing the public/dist/ directory from billionmail-core-billionmail-1 container..."++# Remove the public/dist/ directory from the billionmail-core-billionmail-1 container+docker exec billionmail-core-billionmail-1 sh -c "rm -rf /opt/billionmail/core/public/dist"+++echo "Copying the public/ directory to billionmail-core-billionmail-1 container..."++# Copy the public directory to the billionmail-core-billionmail-1 container+docker cp public/. billionmail-core-billionmail-1:/opt/billionmail/core/public/+++echo "Copying the manifest/ directory to billionmail-core-billionmail-1 container..."++# Copy the manifest/ directory to the billionmail-core-billionmail-1 container+docker cp manifest/. billionmail-core-billionmail-1:/opt/billionmail/core/manifest/+++echo "Copying the template/ directory to billionmail-core-billionmail-1 container..."++# Copy the template/ directory to the billionmail-core-billionmail-1 container+docker cp template/. billionmail-core-billionmail-1:/opt/billionmail/core/template/++echo "Restarting billionmail-core-billionmail-1 container..."# Restart the billionmail-core-billionmail-1 container to apply changes