Skip to content

Commit

Permalink
Update naming patterns to match non-catalog funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
nathancoleman committed May 21, 2024
1 parent d630fa6 commit 4018d6b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import (
const (
exportedServicesEndpointLabel = "list.exportedServices"

// CatalogExportedServicesQuerySleepTime is the amount of time to sleep between
// ListExportedServicesQuerySleepTime is the amount of time to sleep between
// queries, since the endpoint does not support blocking queries.
CatalogExportedServicesQuerySleepTime = 15 * time.Second
ListExportedServicesQuerySleepTime = 15 * time.Second
)

// Ensure implements
var _ Dependency = (*CatalogExportedServicesQuery)(nil)
var _ Dependency = (*ListExportedServicesQuery)(nil)

// CatalogExportedServicesQuery is the representation of a requested catalog partitions
// ListExportedServicesQuery is the representation of a requested exported services
// dependency from inside a template.
type CatalogExportedServicesQuery struct {
type ListExportedServicesQuery struct {
stopCh chan struct{}
partition string
}
Expand Down Expand Up @@ -57,15 +57,15 @@ func fromConsulExportedService(svc capi.ResolvedExportedService) ExportedService
}
}

// NewCatalogExportedServicesQuery parses a string of the format @dc.
func NewCatalogExportedServicesQuery(s string) (*CatalogExportedServicesQuery, error) {
return &CatalogExportedServicesQuery{
// NewListExportedServicesQuery parses a string of the format @dc.
func NewListExportedServicesQuery(s string) (*ListExportedServicesQuery, error) {
return &ListExportedServicesQuery{
stopCh: make(chan struct{}, 1),
partition: s,
}, nil
}

func (c *CatalogExportedServicesQuery) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error) {
func (c *ListExportedServicesQuery) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error) {
opts = opts.Merge(&QueryOptions{
ConsulPartition: c.partition,
})
Expand All @@ -85,12 +85,12 @@ func (c *CatalogExportedServicesQuery) Fetch(clients *ClientSet, opts *QueryOpti
// This is probably okay given the frequency in which partitions actually
// change, but is technically not edge-triggering.
if opts.WaitIndex != 0 {
log.Printf("[TRACE] %s: long polling for %s", c, CatalogDatacentersQuerySleepTime)
log.Printf("[TRACE] %s: long polling for %s", c, ListExportedServicesQuerySleepTime)

select {
case <-c.stopCh:
return nil, nil, ErrStopped
case <-time.After(CatalogExportedServicesQuerySleepTime):
case <-time.After(ListExportedServicesQuerySleepTime):
}
}

Expand Down Expand Up @@ -126,18 +126,18 @@ func (c *CatalogExportedServicesQuery) Fetch(clients *ClientSet, opts *QueryOpti

// CanShare returns if this dependency is shareable.
// TODO What is this?
func (c *CatalogExportedServicesQuery) CanShare() bool {
func (c *ListExportedServicesQuery) CanShare() bool {
return true
}

func (c *CatalogExportedServicesQuery) String() string {
func (c *ListExportedServicesQuery) String() string {
return exportedServicesEndpointLabel
}

func (c *CatalogExportedServicesQuery) Stop() {
func (c *ListExportedServicesQuery) Stop() {
close(c.stopCh)
}

func (c *CatalogExportedServicesQuery) Type() Type {
func (c *ListExportedServicesQuery) Type() Type {
return TypeConsul
}
2 changes: 1 addition & 1 deletion template/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func exportedServicesFunc(b *Brain, used, missing *dep.Set) func(...string) ([]d
return result, errors.New("exportedServices: wrong number of arguments, expected 0 or 1")
}

d, err := dep.NewCatalogExportedServicesQuery(strings.Join(s, ""))
d, err := dep.NewListExportedServicesQuery(strings.Join(s, ""))
if err != nil {
return result, err
}
Expand Down

0 comments on commit 4018d6b

Please sign in to comment.