feat: 换到 Gin 主流栈并补齐运维能力
HTTP 用 Gin,配置用 Viper,日志用 zap,数据用 sqlx;保留原有接口与会商行为。 顺带补上就绪探活、请求号、滚动日志、systemd 与 Dockerfile。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
0c45b86d67
commit
bd427b57a1
26 files changed
+1213
-302
No files matched your search
@@ -1,20 +1,21 @@
|
||||
package worker
|
||||
|
||||
import (
|
||||
"log"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"git.gozeros.com/wsk/eightbf-analysis-go/internal/domain"
|
||||
"git.gozeros.com/wsk/eightbf-analysis-go/internal/logging"
|
||||
"git.gozeros.com/wsk/eightbf-analysis-go/internal/repo"
|
||||
)
|
||||
|
||||
// LiveWorker 定时扫 queued,最多并发 2 场交给 LiveChainRunner。
|
||||
// LiveWorker 定时扫 queued,最多并发 MaxInflight 场交给 LiveChainRunner。
|
||||
type LiveWorker struct {
|
||||
Repo *repo.JobRepo
|
||||
Runner *LiveChainRunner
|
||||
PollEvery time.Duration
|
||||
inflight int32
|
||||
Repo *repo.JobRepo
|
||||
Runner *LiveChainRunner
|
||||
PollEvery time.Duration
|
||||
MaxInflight int32
|
||||
inflight int32
|
||||
}
|
||||
|
||||
func (w *LiveWorker) Start() {
|
||||
@@ -31,22 +32,26 @@ func (w *LiveWorker) Start() {
|
||||
}
|
||||
|
||||
func (w *LiveWorker) poll() {
|
||||
if atomic.LoadInt32(&w.inflight) >= 2 {
|
||||
max := w.MaxInflight
|
||||
if max < 1 {
|
||||
max = 2
|
||||
}
|
||||
if atomic.LoadInt32(&w.inflight) >= max {
|
||||
return
|
||||
}
|
||||
queued, err := w.Repo.FindQueuedJobs()
|
||||
if err != nil {
|
||||
log.Printf("LiveWorker 扫队列失败: %v", err)
|
||||
logging.L.Warnw("LiveWorker 扫队列失败", "err", err)
|
||||
return
|
||||
}
|
||||
for _, job := range queued {
|
||||
if atomic.LoadInt32(&w.inflight) >= 2 {
|
||||
if atomic.LoadInt32(&w.inflight) >= max {
|
||||
break
|
||||
}
|
||||
job.Status = domain.StatusRunning
|
||||
job.Phase = "claimed"
|
||||
if err := w.Repo.UpdateProgress(job); err != nil {
|
||||
log.Printf("LiveWorker 占坑失败 jobId=%s: %v", job.ID, err)
|
||||
logging.L.Warnw("LiveWorker 占坑失败", logging.KeyJobID, job.ID, "err", err)
|
||||
continue
|
||||
}
|
||||
atomic.AddInt32(&w.inflight, 1)
|
||||
@@ -57,7 +62,13 @@ func (w *LiveWorker) poll() {
|
||||
if err != nil || fresh == nil {
|
||||
return
|
||||
}
|
||||
log.Printf("开始真模型会商 jobId=%s", jobID)
|
||||
logging.L.Infow("开始真模型会商",
|
||||
logging.KeyJobID, jobID,
|
||||
logging.KeyRequestID, fresh.RequestID,
|
||||
logging.KeyTaskID, fresh.TaskID,
|
||||
logging.KeyModel, fresh.Model,
|
||||
logging.KeyStatus, fresh.Status,
|
||||
)
|
||||
w.Runner.Run(fresh)
|
||||
}()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user