[#222] auditsvc: Refactor audit task
Resolve containedctx linter. Cancel task by listen cancel. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
3dbff0a478
commit
e8d340287f
10 changed files with 66 additions and 58 deletions
|
@ -46,15 +46,21 @@ func (ap *Processor) processStartAudit(epoch uint64) {
|
|||
return
|
||||
}
|
||||
|
||||
var auditCtx context.Context
|
||||
auditCtx, ap.prevAuditCanceler = context.WithCancel(context.Background())
|
||||
cancelChannel := make(chan struct{})
|
||||
ap.prevAuditCanceler = func() {
|
||||
select {
|
||||
case <-cancelChannel: // already closed
|
||||
default:
|
||||
close(cancelChannel)
|
||||
}
|
||||
}
|
||||
|
||||
pivot := make([]byte, sha256.Size)
|
||||
|
||||
ap.startAuditTasksOnContainers(auditCtx, containers, log, pivot, nm, epoch)
|
||||
ap.startAuditTasksOnContainers(cancelChannel, containers, log, pivot, nm, epoch)
|
||||
}
|
||||
|
||||
func (ap *Processor) startAuditTasksOnContainers(ctx context.Context, containers []cid.ID, log *zap.Logger, pivot []byte, nm *netmap.NetMap, epoch uint64) {
|
||||
func (ap *Processor) startAuditTasksOnContainers(cancelChannel <-chan struct{}, containers []cid.ID, log *zap.Logger, pivot []byte, nm *netmap.NetMap, epoch uint64) {
|
||||
for i := range containers {
|
||||
cnr, err := cntClient.Get(ap.containerClient, containers[i]) // get container structure
|
||||
if err != nil {
|
||||
|
@ -107,18 +113,14 @@ func (ap *Processor) startAuditTasksOnContainers(ctx context.Context, containers
|
|||
epoch: epoch,
|
||||
rep: ap.reporter,
|
||||
}).
|
||||
WithAuditContext(ctx).
|
||||
WithCancelChannel(cancelChannel).
|
||||
WithContainerID(containers[i]).
|
||||
WithStorageGroupList(storageGroups).
|
||||
WithContainerStructure(cnr.Value).
|
||||
WithContainerNodes(nodes).
|
||||
WithNetworkMap(nm)
|
||||
|
||||
if err := ap.taskManager.PushTask(auditTask); err != nil {
|
||||
ap.log.Error("could not push audit task",
|
||||
zap.String("error", err.Error()),
|
||||
)
|
||||
}
|
||||
ap.taskManager.PushTask(auditTask)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue