Files
iotlcm/server/internal/logic/imeiqueue/queue.go
T
MiFaZhan 59eb34976a chore: 初始开源发布
iotlcm-admin-svr:管理后台服务。

- Go module:iotlcm → git.5iot.com/iotlcm-public/iotlcm-admin-svr(729 文件)
- 凭据与地址脱敏:JWT signingKey(含代码里的 MustGet 默认值)、
  MySQL DSN、Redis 口令、告警邮件发件人邮箱全部改为占位;
  私网 IP → 文档地址段;库名 xiujie_admin → iotlcm
- 真实手机号/邮箱 → 合法 11 位编造号 / example.com
- 移除内部资产:CI 触发器、过时 DDL(sql/db_iotlcm.sql)、
  私有依赖 go get 行、明文 registry 登录口令
- 启动 banner 统一 IOTLCM 方块字 + 社区惯例署名
- Dockerfile 改用公共基础镜像
- 拼错的 RADEME.md → README.md,README 重写
- 需要真实数据库的用例改为可用 IOTLCM_TEST_WITH_DB=1 显式启用
- 补 Apache-2.0 LICENSE,LF 行尾 + .gitattributes

数据库 schema 不随本仓发布(生产 DDL 已过时),README 已说明。
2026-10-23 14:48:30 +08:00

66 lines
2.0 KiB
Go

package imeiqueue
import (
"context"
"fmt"
"time"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/consts"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/library/rabbitmq"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/model"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/service"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/utility/uuid32"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
)
const fullSyncOperation = "imei_full_sync"
type sImeiQueue struct{}
var (
imeiNow = time.Now
imeiRunID = uuid32.S
imeiRabbitEnabled = rabbitmq.Enabled
imeiPublish = rabbitmq.Publish
)
func init() { service.RegisterImeiQueue(New()) }
func New() *sImeiQueue { return &sImeiQueue{} }
func (s *sImeiQueue) StartImeiRun(ctx context.Context) (string, error) {
return s.StartImeiRunScoped(ctx, nil)
}
// StartImeiRunScoped starts an IMEI run restricted to scope.Channels. A nil
// scope, or one whose channels normalize to empty, starts a full sync.
//
// The runId prefix keeps IMEI runs distinguishable from status runs in logs and
// in the Redis key space (each chain has its own prefix anyway).
func (s *sImeiQueue) StartImeiRunScoped(ctx context.Context, scope *model.SyncScope) (string, error) {
if ctx == nil {
ctx = context.Background()
}
normalized, err := model.NormalizeScope(scope)
if err != nil {
return "", err
}
if !imeiRabbitEnabled(ctx) {
return "", gerror.New("imei queue start skipped: rabbitmq is disabled")
}
now := imeiNow()
message := model.ImeiQueueStartMessage{
RunID: fmt.Sprintf("imei-%s-%s", now.Format("20060102150405"), imeiRunID()),
Operation: fullSyncOperation,
TriggeredAt: now.Format(time.RFC3339),
Scope: normalized,
}
if err := imeiPublish(ctx, consts.QueueImeiQueueStart, message); err != nil {
return "", gerror.Wrap(err, "publish imei queue start")
}
g.Log().Infof(ctx, "event=imei_queue_trigger status=published runId=%s scopeChannels=%d", message.RunID, normalized.ChannelCount())
return message.RunID, nil
}