Skip to content

Commit

Permalink
Makes changes suggested in the PR, fixes logic for filtering packages…
Browse files Browse the repository at this point in the history
…, removes both the timeout and only keeps the ticker
  • Loading branch information
ddebarros committed Oct 17, 2022
1 parent b34106a commit 75be2ed
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
32 changes: 21 additions & 11 deletions commands/activations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
}

Expand All @@ -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 {
Expand Down
17 changes: 17 additions & 0 deletions do/serverless.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit 75be2ed

Please sign in to comment.