Skip to content

Commit

Permalink
Add logs to show the status of orphan-command-cleaner (#1475)
Browse files Browse the repository at this point in the history
**What this PR does / why we need it**:

**Which issue(s) this PR fixes**:

Fixes #

**Does this PR introduce a user-facing change?**:
<!--
If no, just write "NONE" in the release-note block below.
-->
```release-note
NONE
```

This PR was merged by Kapetanios.
  • Loading branch information
nghialv authored Jan 25, 2021
1 parent 0a20165 commit 1928cc4
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pkg/app/ops/orphancommandcleaner/orphancommandcleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ func NewOrphanCommandCleaner(
}

func (c *OrphanCommandCleaner) Run(ctx context.Context) error {
c.logger.Info("start running OrphanCommandCleaner")

t := time.NewTicker(interval)
for {
select {
case <-ctx.Done():
c.logger.Info("OrphanCommandCleaner has been stopped")
return nil

case <-t.C:
start := time.Now()
if err := c.updateOrphanCommandsStatus(ctx); err == nil {
Expand Down Expand Up @@ -63,15 +67,21 @@ func (c *OrphanCommandCleaner) updateOrphanCommandsStatus(ctx context.Context) e
}
commands, err := c.commandstore.ListCommands(ctx, opts)
if err != nil {
c.logger.Error("failed to list not-handled commands", zap.Error(err))
return err
}

for _, command := range commands {
if err := c.commandstore.UpdateCommand(ctx, command.Id, func(cmd *model.Command) error {
err := c.commandstore.UpdateCommand(ctx, command.Id, func(cmd *model.Command) error {
cmd.Status = model.CommandStatus_COMMAND_TIMEOUT
return nil
}); err != nil {
c.logger.Error("failed to update orphan command", zap.Error(err), zap.String("id", command.Id), zap.String("type", command.Type.String()))
})
if err != nil {
c.logger.Error("failed to mark orphan command as timed out",
zap.String("id", command.Id),
zap.String("type", command.Type.String()),
zap.Error(err),
)
}
}

Expand Down

0 comments on commit 1928cc4

Please sign in to comment.