-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new cmd to remove triggers (#790)
* feat(cli): Added new cmd There is a problem - one of teams of Moira users have unused triggers. So it is a trash in database. Added command to remove triggers which have ID starting with prefix. * refactor(cli): Renamed var There was linter error and bug - shadow of global variable "triggers". Renamed global var for more detail because it has bigger scope that local var.
- Loading branch information
1 parent
aff7e3e
commit d33454b
Showing
7 changed files
with
132 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/moira-alert/moira" | ||
) | ||
|
||
func handleRemoveTriggersStartWith(logger moira.Logger, database moira.Database, prefix string) error { | ||
triggers, err := database.GetTriggerIDsStartWith(prefix) | ||
if err != nil { | ||
return fmt.Errorf("can't get trigger IDs start with prefix %s: %w", prefix, err) | ||
} | ||
|
||
// Added delay because command is potentially dangerous and can delete unwanted triggers | ||
const delay = 10 * time.Second | ||
logger.Infof("%d triggers start with %s would be removed after %s", len(triggers), prefix, delay) | ||
logger.Info("You can cancel execution by Ctrl+C") | ||
time.Sleep(delay) | ||
|
||
logger.Infof("Removing triggers start with prefix %s has started", prefix) | ||
for _, id := range triggers { | ||
err := database.RemoveTrigger(id) | ||
if err != nil { | ||
return fmt.Errorf("can't remove trigger with id %s: %w", id, err) | ||
} | ||
} | ||
logger.Infof("Removing triggers start with prefix %s has finished", prefix) | ||
logger.Infof("Count of deleted is %d", len(triggers)) | ||
logger.Infof("Removed triggers: %s", triggers) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.