asynccharmdownloader

package
v0.0.0-...-f88c608 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2025 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Manifold

func Manifold(cfg ManifoldConfig) dependency.Manifold

Manifold returns a Manifold that encapsulates the charmdownloader worker.

func NewAsyncDownloadWorker

func NewAsyncDownloadWorker(
	appID application.ID,
	applicationService ApplicationService,
	downloader Downloader,
	clock clock.Clock,
	logger logger.Logger,
) worker.Worker

NewAsyncDownloadWorker creates a new async worker that downloads charms for the specified application.

func NewHTTPClient

func NewHTTPClient(ctx context.Context, getter corehttp.HTTPClientGetter) (corehttp.HTTPClient, error)

NewHTTPClient creates a new HTTP client.

Types

type ApplicationService

type ApplicationService interface {
	// WatchApplicationsWithPendingCharms returns a watcher that notifies of
	// changes to applications that reference charms that have not yet been
	// downloaded.
	// Each string will be an individual application ID. It's possible to
	// have the same application ID multiple times in the list.
	WatchApplicationsWithPendingCharms(ctx context.Context) (watcher.StringsWatcher, error)

	// GetAsyncCharmDownloadInfo reserves a charm download slot for the specified
	// application. If the charm is already being downloaded, the method will
	// return [applicationerrors.AlreadyDownloadingCharm]. The charm download
	// information is returned which includes the charm name, origin and the
	// digest.
	GetAsyncCharmDownloadInfo(ctx context.Context, appID application.ID) (domainapplication.CharmDownloadInfo, error)

	// ResolveCharmDownload resolves the charm download slot for the specified
	// application. The method will update the charm with the specified charm
	// information.
	ResolveCharmDownload(ctx context.Context, appID application.ID, resolve domainapplication.ResolveCharmDownload) error
}

ApplicationService describes the API exposed by the charm downloader facade.

type Config

type Config struct {
	ApplicationService     ApplicationService
	HTTPClientGetter       corehttp.HTTPClientGetter
	NewHTTPClient          NewHTTPClientFunc
	NewDownloader          NewDownloaderFunc
	NewAsyncDownloadWorker NewAsyncDownloadWorkerFunc
	Logger                 logger.Logger
	Clock                  clock.Clock
}

Config defines the operation of a Worker.

func (Config) Validate

func (cfg Config) Validate() error

Validate returns an error if cfg cannot drive a Worker.

type Downloader

type Downloader interface {
	// Download looks up the requested charm using the appropriate store, downloads
	// it to a temporary file and passes it to the configured storage API so it can
	// be persisted.
	//
	// The resulting charm is verified to be the right hash. It expected that the
	// origin will always have the correct hash following this call.
	//
	// Returns [ErrInvalidHash] if the hash of the downloaded charm does not match
	// the expected hash.
	Download(ctx context.Context, curl *url.URL, hash string) (*charmdownloader.DownloadResult, error)
}

Downloader is responsible for downloading charms from the charm store.

func NewDownloader

func NewDownloader(httpClient charmhub.HTTPClient, logger logger.Logger) Downloader

NewDownloader creates a new Downloader instance.

type ManifoldConfig

type ManifoldConfig struct {
	DomainServicesName     string
	HTTPClientName         string
	NewDownloader          NewDownloaderFunc
	NewHTTPClient          NewHTTPClientFunc
	NewAsyncDownloadWorker NewAsyncDownloadWorkerFunc
	Logger                 logger.Logger
	Clock                  clock.Clock
}

ManifoldConfig describes the resources used by the charmdownloader worker.

func (ManifoldConfig) Validate

func (cfg ManifoldConfig) Validate() error

Validate is called by start to check for bad configuration.

type NewAsyncDownloadWorkerFunc

type NewAsyncDownloadWorkerFunc func(
	appID application.ID,
	applicationService ApplicationService,
	downloader Downloader,
	clock clock.Clock,
	logger logger.Logger,
) worker.Worker

NewAsyncDownloadWorkerFunc is a function that creates a new async worker.

type NewDownloaderFunc

type NewDownloaderFunc func(charmhub.HTTPClient, logger.Logger) Downloader

NewDownloaderFunc is a function that creates a new Downloader.

type NewHTTPClientFunc

type NewHTTPClientFunc func(context.Context, corehttp.HTTPClientGetter) (corehttp.HTTPClient, error)

NewHTTPClientFunc is a function that creates a new HTTP client.

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

Worker watches applications that reference charms that have not yet been downloaded and triggers an asynchronous download request for each one.

func NewWorker

func NewWorker(config Config) (*Worker, error)

NewWorker returns a new Worker worker.

func (*Worker) Kill

func (w *Worker) Kill()

Kill is part of the worker.Worker interface.

func (*Worker) Wait

func (w *Worker) Wait() error

Wait is part of the worker.Worker interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL