retry

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package retry is the retry server responsible for interacting with GitHub APIs to retry failed events.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BigQuery

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

BigQuery provides a client and dataset identifiers.

func NewBigQuery

func NewBigQuery(ctx context.Context, projectID, datasetID string, opts ...option.ClientOption) (*BigQuery, error)

NewBigQuery creates a new instance of a BigQuery client.

func (*BigQuery) Close

func (bq *BigQuery) Close() error

Close releases any resources held by the BigQuery client.

func (*BigQuery) DeliveryEventExists

func (bq *BigQuery) DeliveryEventExists(ctx context.Context, eventsTableID, deliveryID string) (bool, error)

Check if an entry with a given delivery_id already exists in the events table, this attempts to prevent duplicate processing of events.

func (*BigQuery) RetrieveCheckpointID

func (bq *BigQuery) RetrieveCheckpointID(ctx context.Context, checkpointTableID string) (string, error)

Retrieve the latest checkpoint cursor value (deliveryID) in the checkpoint table. This is used by the retry service.

func (*BigQuery) WriteCheckpointID

func (bq *BigQuery) WriteCheckpointID(ctx context.Context, checkpointTableID, deliveryID, createdAt string) error

Write the latest checkpoint that was successfully processed. This is used by the retry service.

type CheckpointEntry

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

CheckpointEntry is the shape of an entry to the checkpoint table.

func (*CheckpointEntry) Save

func (ce *CheckpointEntry) Save() (map[string]bigquery.Value, string, error)

Save implements the ValueSaver interface for a CheckpointEntry. A random insertID is generated by the library to facilitate deduplication.

type Config

type Config struct {
	GitHubAppID       string        `env:"GITHUB_APP_ID,required"`
	GitHubPrivateKey  string        `env:"GITHUB_PRIVATE_KEY,required"`
	BigQueryProjectID string        `env:"BIG_QUERY_PROJECT_ID,default=$PROJECT_ID"`
	BucketName        string        `env:"BUCKET_NAME,required"`
	CheckpointTableID string        `env:"CHECKPOINT_TABLE_ID,required"`
	EventsTableID     string        `env:"EVENTS_TABLE_ID,required"`
	DatasetID         string        `env:"DATASET_ID,required"`
	LockTTLClockSkew  time.Duration `env:"LOCK_TTL_CLOCK_SKEW,default=10s"`
	LockTTL           time.Duration `env:"LOCK_TTL,default=5m"`
	ProjectID         string        `env:"PROJECT_ID,required"`
	Port              string        `env:"PORT,default=8080"`
}

Config defines the set of environment variables required for running the retry service.

func NewConfig

func NewConfig(ctx context.Context) (*Config, error)

NewConfig creates a new Config from environment variables.

func (*Config) ToFlags

func (cfg *Config) ToFlags(set *cli.FlagSet) *cli.FlagSet

ToFlags binds the config to the cli.FlagSet and returns it.

func (*Config) Validate

func (cfg *Config) Validate() error

Validate validates the retry config after load.

type Datastore

type Datastore interface {
	RetrieveCheckpointID(ctx context.Context, checkpointTableID string) (string, error)
	WriteCheckpointID(ctx context.Context, checkpointTableID, deliveryID, createdAt string) error
	DeliveryEventExists(ctx context.Context, eventsTableID, deliveryID string) (bool, error)
	Close() error
}

Datastore adheres to the interaction the retry service has with a datastore.

type GitHubSource

type GitHubSource interface {
	ListDeliveries(ctx context.Context, opts *github.ListCursorOptions) ([]*github.HookDelivery, *github.Response, error)
	RedeliverEvent(ctx context.Context, deliveryID int64) error
}

GitHubSource aheres to the interaction the retyr service has with GitHub APIs.

type MockDatastore

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

func (*MockDatastore) Close

func (f *MockDatastore) Close() error

func (*MockDatastore) DeliveryEventExists

func (f *MockDatastore) DeliveryEventExists(ctx context.Context, eventsTableID, deliveryID string) (bool, error)

func (*MockDatastore) RetrieveCheckpointID

func (f *MockDatastore) RetrieveCheckpointID(ctx context.Context, checkpointTableID string) (string, error)

func (*MockDatastore) WriteCheckpointID

func (f *MockDatastore) WriteCheckpointID(ctx context.Context, checkpointTableID, deliveryID, createdAt string) error

func (*MockDatastore) WriteFailureEvent

func (f *MockDatastore) WriteFailureEvent(ctx context.Context, failureEventTableID, deliveryID, createdAt string) error

type MockGitHub

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

func (*MockGitHub) ListDeliveries

func (m *MockGitHub) ListDeliveries(ctx context.Context, opts *github.ListCursorOptions) ([]*github.HookDelivery, *github.Response, error)

func (*MockGitHub) RedeliverEvent

func (m *MockGitHub) RedeliverEvent(ctx context.Context, deliveryID int64) error

type MockLock

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

func (*MockLock) Acquire

func (m *MockLock) Acquire(context.Context, time.Duration) error

func (*MockLock) Close

func (m *MockLock) Close(context.Context) error

type RetryClientOptions

type RetryClientOptions struct {
	BigQueryClientOpts      []option.ClientOption
	GCSLockClientOpts       []option.ClientOption
	DatastoreClientOverride Datastore        // used for unit testing
	GCSLockClientOverride   gcslock.Lockable // used for unit testing
	GitHubOverride          GitHubSource     // used for unit testing
}

RetryClientOptions encapsulate client config options as well as dependency implementation overrides.

type Server

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

func NewServer

func NewServer(ctx context.Context, cfg *Config, rco *RetryClientOptions) (*Server, error)

NewServer creates a new HTTP server implementation that will handle communication with GitHub APIs.

func (*Server) Close

func (s *Server) Close() error

Close handles the graceful shutdown of the retry server.

func (*Server) Routes

func (s *Server) Routes(ctx context.Context) http.Handler

Routes creates a ServeMux of all of the routes that this Router supports.

Jump to

Keyboard shortcuts

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