merged from gramsrv upstream
This commit is contained in:
parent
79c64ee916
commit
21a0856587
651 changed files with 54774 additions and 4590 deletions
|
|
@ -2,6 +2,7 @@ package rpc
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
|
@ -11,19 +12,26 @@ import (
|
|||
|
||||
// SuggestedPostDispatcher publishes scheduled suggestions and resolves paid
|
||||
// escrow after the minimum live age (or refunds it when the post is deleted).
|
||||
// Store-side row locks make multiple server instances safe.
|
||||
// Store-side per-key claims and row locks make multiple server instances safe.
|
||||
type SuggestedPostDispatcher struct {
|
||||
router *Router
|
||||
log *zap.Logger
|
||||
interval time.Duration
|
||||
batch int
|
||||
enqueue func(context.Context, int64, domain.ToggleSuggestedPostApprovalResult) error
|
||||
}
|
||||
|
||||
func NewSuggestedPostDispatcher(router *Router, log *zap.Logger) *SuggestedPostDispatcher {
|
||||
if log == nil {
|
||||
log = zap.NewNop()
|
||||
}
|
||||
return &SuggestedPostDispatcher{router: router, log: log, interval: time.Second, batch: 50}
|
||||
return &SuggestedPostDispatcher{
|
||||
router: router, log: log, interval: time.Second, batch: 50,
|
||||
enqueue: func(ctx context.Context, originUserID int64, result domain.ToggleSuggestedPostApprovalResult) error {
|
||||
router.enqueueSuggestedPostApprovalFanout(ctx, originUserID, result)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *SuggestedPostDispatcher) Run(ctx context.Context) {
|
||||
|
|
@ -47,13 +55,17 @@ func (d *SuggestedPostDispatcher) DispatchOnce(ctx context.Context) bool {
|
|||
if !ok {
|
||||
return false
|
||||
}
|
||||
results, err := service.ProcessSuggestedPostLifecycle(ctx, domain.SuggestedPostLifecycleRequest{Now: int(d.router.clock.Now().Unix()), Limit: d.batch})
|
||||
if err != nil {
|
||||
d.log.Warn("process suggested post lifecycle", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
results, dispatchErr := service.ProcessSuggestedPostLifecycle(ctx, domain.SuggestedPostLifecycleRequest{Now: int(d.router.clock.Now().Unix()), Limit: d.batch})
|
||||
enqueued := false
|
||||
for _, result := range results {
|
||||
d.router.enqueueSuggestedPostApprovalFanout(ctx, 0, result)
|
||||
if err := d.enqueue(ctx, 0, result); err != nil {
|
||||
dispatchErr = errors.Join(dispatchErr, err)
|
||||
continue
|
||||
}
|
||||
enqueued = true
|
||||
}
|
||||
return len(results) > 0
|
||||
if dispatchErr != nil {
|
||||
d.log.Warn("dispatch suggested post lifecycle", zap.Error(dispatchErr))
|
||||
}
|
||||
return enqueued
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue