github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/resource/workers/charmstorepoller.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package workers 5 6 import ( 7 "time" 8 9 "github.com/juju/errors" 10 charmresource "gopkg.in/juju/charm.v6/resource" 11 "gopkg.in/juju/names.v2" 12 13 "github.com/juju/juju/charmstore" 14 ) 15 16 // DataStore exposes the functionality of Juju state needed here. 17 type DataStore interface { 18 // SetCharmStoreResources sets the "polled from the charm store" 19 // resources for the application to the provided values. 20 SetCharmStoreResources(applicationID string, info []charmresource.Resource, lastPolled time.Time) error 21 } 22 23 // LatestCharmHandler implements apiserver/facades/controller/charmrevisionupdater.LatestCharmHandler. 24 type LatestCharmHandler struct { 25 store DataStore 26 } 27 28 // NewLatestCharmHandler returns a LatestCharmHandler that uses the 29 // given data store. 30 func NewLatestCharmHandler(store DataStore) *LatestCharmHandler { 31 return &LatestCharmHandler{ 32 store: store, 33 } 34 } 35 36 // HandleLatest implements apiserver/facades/controller/charmrevisionupdater.LatestCharmHandler 37 // by storing the charm's resources in state. 38 func (handler LatestCharmHandler) HandleLatest(applicationID names.ApplicationTag, info charmstore.CharmInfo) error { 39 if err := handler.store.SetCharmStoreResources(applicationID.Id(), info.LatestResources, info.Timestamp); err != nil { 40 return errors.Trace(err) 41 } 42 return nil 43 }