MCPcopy Create free account
hub / github.com/GoSimplicity/LinkMe / ProcessTask

Method ProcessTask

internal/job/refresh_cache.go:38–66  ·  view source on GitHub ↗
(ctx context.Context, t *asynq.Task)

Source from the content-addressed store, hash-verified

36}
37
38func (r *RefreshCacheTask) ProcessTask(ctx context.Context, t *asynq.Task) error {
39 var p Payload
40 if err := json.Unmarshal(t.Payload(), &p); err != nil {
41 r.l.Error("解析任务载荷失败", zap.Error(err))
42 return fmt.Errorf("解析任务载荷失败: %w", err)
43 }
44
45 if p.RefreshType == 0 || p.Key == "" {
46 return fmt.Errorf("无效的刷新参数: 类型=%d, 键=%s", p.RefreshType, p.Key)
47 }
48
49 ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
50 defer cancel()
51
52 postIdStr := fmt.Sprint(p.PostId)
53 logger := r.l.With(zap.Uint("post_id", p.PostId), zap.String("key", p.Key))
54
55 // 根据刷新类型选择不同的删除策略
56 switch p.RefreshType {
57 case RefreshTypePub:
58 return r.refreshPubCache(ctx, p.Key, postIdStr, logger)
59 case RefreshTypeNormal:
60 return r.refreshNormalCache(ctx, p.Key, postIdStr, logger)
61 case RefreshTypeAll:
62 return r.refreshAllCache(ctx, p.Key, postIdStr, logger)
63 default:
64 return fmt.Errorf("不支持的刷新类型: %d", p.RefreshType)
65 }
66}
67
68// 刷新发布的帖子缓存
69func (r *RefreshCacheTask) refreshPubCache(ctx context.Context, key, postId string, logger *zap.Logger) error {

Callers

nothing calls this directly

Calls 3

refreshPubCacheMethod · 0.95
refreshNormalCacheMethod · 0.95
refreshAllCacheMethod · 0.95

Tested by

no test coverage detected