refactor: use framework for running function against all apps
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
```
|
||||
logs <app> [-h] [-t] [-n num] [-q] [-p process] # Display recent log output
|
||||
logs:failed [<app>] # Shows the last failed deploy logs
|
||||
logs:failed [--parallel count] [--all|<app>] # Shows the last failed deploy logs
|
||||
```
|
||||
|
||||
## Usage
|
||||
@@ -46,8 +46,8 @@ You can retrieve these logs by using the `logs:failed` command
|
||||
dokku logs:failed node-js-app
|
||||
```
|
||||
|
||||
You can also retrieve the failed logs for each app:
|
||||
You may also fetch all failed app logs by using the `--all` flag.
|
||||
|
||||
```shell
|
||||
dokku logs:failed node-js-app
|
||||
dokku logs:failed --all
|
||||
```
|
||||
|
||||
@@ -43,13 +43,13 @@ func RunCommandAgainstAllApps(command ParallelCommand, commandName string, paral
|
||||
}
|
||||
|
||||
if runInSerial {
|
||||
return runCommandAgainstAllAppsSerially(command, commandName)
|
||||
return RunCommandAgainstAllAppsSerially(command, commandName)
|
||||
}
|
||||
|
||||
return runCommandAgainstAllAppsInParallel(command, commandName, parallelCount)
|
||||
return RunCommandAgainstAllAppsInParallel(command, commandName, parallelCount)
|
||||
}
|
||||
|
||||
func runCommandAgainstAllAppsInParallel(command ParallelCommand, commandName string, parallelCount int) error {
|
||||
func RunCommandAgainstAllAppsInParallel(command ParallelCommand, commandName string, parallelCount int) error {
|
||||
apps, err := DokkuApps()
|
||||
if err != nil {
|
||||
LogWarn(err.Error())
|
||||
@@ -68,7 +68,7 @@ func runCommandAgainstAllAppsInParallel(command ParallelCommand, commandName str
|
||||
return err
|
||||
}
|
||||
|
||||
func runCommandAgainstAllAppsSerially(command ParallelCommand, commandName string) error {
|
||||
func RunCommandAgainstAllAppsSerially(command ParallelCommand, commandName string) error {
|
||||
apps, err := DokkuApps()
|
||||
if err != nil {
|
||||
LogWarn(err.Error())
|
||||
|
||||
6
plugins/logs/go.sum
Normal file
6
plugins/logs/go.sum
Normal file
@@ -0,0 +1,6 @@
|
||||
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 h1:sDMmm+q/3+BukdIpxwO365v/Rbspp2Nt5XntgQRXq8Q=
|
||||
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM=
|
||||
github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27 h1:HHUr4P/aKh4quafGxDT9LDasjGdlGkzLbfmmrlng3kA=
|
||||
github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27/go.mod h1:VQx0hjo2oUeQkQUET7wRwradO6f+fN5jzXgB/zROxxE=
|
||||
github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3 h1:utdYOikI1XjNtTFGCwSM6OmFJblU4ld4gACoJsbadJg=
|
||||
github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||
17
plugins/logs/logs.go
Normal file
17
plugins/logs/logs.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package logs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
// GetFailedLogs outputs failed deploy logs for a given app
|
||||
func GetFailedLogs(appName string) error {
|
||||
common.LogInfo2Quiet(fmt.Sprintf("%s failed deploy logs", appName))
|
||||
s := common.GetAppScheduler(appName)
|
||||
if err := common.PlugnTrigger("scheduler-logs-failed", s, appName); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -19,9 +19,10 @@ func main() {
|
||||
switch subcommand {
|
||||
case "failed":
|
||||
args := flag.NewFlagSet("logs:failed", flag.ExitOnError)
|
||||
allApps := args.Bool("all", false, "--all: restore all apps")
|
||||
args.Parse(os.Args[2:])
|
||||
appName := args.Arg(0)
|
||||
err = logs.CommandFailed(appName)
|
||||
err = logs.CommandFailed(appName, *allApps)
|
||||
default:
|
||||
common.LogFail(fmt.Sprintf("Invalid plugin subcommand call: %s", subcommand))
|
||||
}
|
||||
|
||||
@@ -33,25 +33,23 @@ func CommandDefault(appName string, num int64, process string, tail, quiet bool)
|
||||
}
|
||||
|
||||
// CommandFailed shows the last failed deploy logs
|
||||
func CommandFailed(appName string) error {
|
||||
if appName == "" {
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, appName := range apps {
|
||||
_ = failedSingle(appName)
|
||||
}
|
||||
return nil
|
||||
func CommandFailed(appName string, allApps bool) error {
|
||||
if allApps {
|
||||
return common.RunCommandAgainstAllAppsSerially(GetFailedLogs, "logs:failed")
|
||||
}
|
||||
return failedSingle(appName)
|
||||
}
|
||||
|
||||
func failedSingle(appName string) error {
|
||||
common.LogInfo2Quiet(fmt.Sprintf("%s failed deploy logs", appName))
|
||||
s := common.GetAppScheduler(appName)
|
||||
if err := common.PlugnTrigger("scheduler-logs-failed", s, appName); err != nil {
|
||||
if appName == "" {
|
||||
common.LogWarn("Restore specified without app, assuming --all")
|
||||
return common.RunCommandAgainstAllAppsSerially(GetFailedLogs, "logs:failed")
|
||||
}
|
||||
|
||||
if err := common.VerifyAppName(appName); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
if err := common.VerifyAppName(appName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return GetFailedLogs(appName)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user