diff --git a/commands/activations.go b/commands/activations.go index 053fa7768..2a0ae8855 100644 --- a/commands/activations.go +++ b/commands/activations.go @@ -362,11 +362,11 @@ func RunActivationsLogs(c *CmdConfig) error { return err } - for _, a := range reverseActivations(actvs) { - if !belongsToPackage(a, packageFlag) { - continue - } + if packageFlag != "" { + actvs = filterPackages(actvs, packageFlag) + } + for _, a := range reverseActivations(actvs) { makeBanner(c.Out, a) printLogs(c.Out, stripFlag, a) fmt.Fprintln(c.Out) @@ -376,7 +376,7 @@ func RunActivationsLogs(c *CmdConfig) error { // Polls the ActivationList API at an interval and prints the results. func pollActivations(wg *sync.WaitGroup, ec chan error, sls do.ServerlessService, writer io.Writer, functionFlag string, packageFlag string) { - ticker := time.NewTicker(time.Second * 1) + ticker := time.NewTicker(time.Second * 5) tc := ticker.C var lastActivationTimestamp int64 = 0 requestLimit := 1 @@ -398,11 +398,15 @@ func pollActivations(wg *sync.WaitGroup, ec chan error, sls do.ServerlessService break } + if packageFlag != "" { + actv = filterPackages(actv, packageFlag) + } + if len(actv) > 0 { for _, activation := range reverseActivations(actv) { _, knownActivation := printedActivations[activation.ActivationID] - if knownActivation || !belongsToPackage(activation, packageFlag) { + if knownActivation { continue } @@ -417,15 +421,21 @@ func pollActivations(wg *sync.WaitGroup, ec chan error, sls do.ServerlessService lastActivationTimestamp = lastItem.Start + 100 requestLimit = 0 } - - time.Sleep(time.Second * 5) } } } -func belongsToPackage(actv whisk.Activation, packageName string) bool { - pkg := displayers.GetActivationPackageName(actv) - return (packageName == "") || (pkg != "") || pkg == packageName +// Filters the activations to only return activations belonging to the package. +func filterPackages(activations []whisk.Activation, packageName string) []whisk.Activation { + filteredActv := []whisk.Activation{} + + for _, activation := range activations { + inPackage := displayers.GetActivationPackageName(activation) == packageName + if inPackage { + filteredActv = append(filteredActv, activation) + } + } + return filteredActv } func reverseActivations(actv []whisk.Activation) []whisk.Activation { diff --git a/do/serverless.go b/do/serverless.go index f1c921249..d766d452f 100644 --- a/do/serverless.go +++ b/do/serverless.go @@ -820,7 +820,11 @@ func (s *serverlessService) GetActivationCount(options whisk.ActivationCountOpti if err != nil { return empty, err } + resp, _, err := s.owClient.Activations.Count(&options) + if err != nil { + return empty, err + } return *resp, err } @@ -831,7 +835,11 @@ func (s *serverlessService) GetActivation(id string) (whisk.Activation, error) { if err != nil { return empty, err } + resp, _, err := s.owClient.Activations.Get(id) + if err != nil { + return empty, err + } return *resp, err } @@ -842,7 +850,12 @@ func (s *serverlessService) GetActivationLogs(id string) (whisk.Activation, erro if err != nil { return empty, err } + resp, _, err := s.owClient.Activations.Logs(id) + if err != nil { + return empty, err + } + return *resp, err } @@ -853,7 +866,11 @@ func (s *serverlessService) GetActivationResult(id string) (whisk.Response, erro if err != nil { return empty, err } + resp, _, err := s.owClient.Activations.Result(id) + if err != nil { + return empty, err + } return *resp, err }