github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/worker/statushistorypruner/manifold.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package statushistorypruner
     5  
     6  import (
     7  	"time"
     8  
     9  	"github.com/juju/errors"
    10  
    11  	"github.com/juju/juju/api/base"
    12  	"github.com/juju/juju/api/statushistory"
    13  	"github.com/juju/juju/worker"
    14  	"github.com/juju/juju/worker/dependency"
    15  )
    16  
    17  // ManifoldConfig describes the resources and configuration on which the
    18  // statushistorypruner worker depends.
    19  type ManifoldConfig struct {
    20  	APICallerName  string
    21  	MaxHistoryTime time.Duration
    22  	MaxHistoryMB   uint
    23  	PruneInterval  time.Duration
    24  	// TODO(fwereade): 2016-03-17 lp:1558657
    25  	NewTimer worker.NewTimerFunc
    26  }
    27  
    28  // Manifold returns a Manifold that encapsulates the statushistorypruner worker.
    29  func Manifold(config ManifoldConfig) dependency.Manifold {
    30  	return dependency.Manifold{
    31  		Inputs: []string{config.APICallerName},
    32  		Start: func(context dependency.Context) (worker.Worker, error) {
    33  			var apiCaller base.APICaller
    34  			if err := context.Get(config.APICallerName, &apiCaller); err != nil {
    35  				return nil, errors.Trace(err)
    36  			}
    37  
    38  			facade := statushistory.NewFacade(apiCaller)
    39  			prunerConfig := Config{
    40  				Facade:         facade,
    41  				MaxHistoryTime: config.MaxHistoryTime,
    42  				MaxHistoryMB:   config.MaxHistoryMB,
    43  				PruneInterval:  config.PruneInterval,
    44  				NewTimer:       config.NewTimer,
    45  			}
    46  			w, err := New(prunerConfig)
    47  			if err != nil {
    48  				return nil, errors.Trace(err)
    49  			}
    50  			return w, nil
    51  		},
    52  	}
    53  }