github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/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  	MaxLogsPerEntity uint
    22  	PruneInterval    time.Duration
    23  	// TODO(fwereade): 2016-03-17 lp:1558657
    24  	NewTimer worker.NewTimerFunc
    25  }
    26  
    27  // Manifold returns a Manifold that encapsulates the statushistorypruner worker.
    28  func Manifold(config ManifoldConfig) dependency.Manifold {
    29  	return dependency.Manifold{
    30  		Inputs: []string{config.APICallerName},
    31  		Start: func(context dependency.Context) (worker.Worker, error) {
    32  			var apiCaller base.APICaller
    33  			if err := context.Get(config.APICallerName, &apiCaller); err != nil {
    34  				return nil, errors.Trace(err)
    35  			}
    36  
    37  			facade := statushistory.NewFacade(apiCaller)
    38  			prunerConfig := Config{
    39  				Facade:           facade,
    40  				MaxLogsPerEntity: config.MaxLogsPerEntity,
    41  				PruneInterval:    config.PruneInterval,
    42  				NewTimer:         config.NewTimer,
    43  			}
    44  			w, err := New(prunerConfig)
    45  			if err != nil {
    46  				return nil, errors.Trace(err)
    47  			}
    48  			return w, nil
    49  		},
    50  	}
    51  }