datastore

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 13 Imported by: 4

Documentation

Index

Constants

View Source
const (
	TargetStatusActive  TargetStatus = "active"
	TargetStatusRunning              = "running"
	TargetStatusSuspend              = "suspend"
	TargetStatusDeleted              = "deleted"
	TargetStatusErr                  = "error"
)

TargetStatus variables

View Source
const (
	RunnerStatusCreated        RunnerStatus = "created"
	RunnerStatusCompleted                   = "completed"
	RunnerStatusReachHardLimit              = "reach_hard_limit"
)

RunnerStatus variables

Variables

View Source
var (
	IsLocked    = "is locked"
	IsNotLocked = "is not locked"
)

Lock values

View Source
var (
	ErrNotFound = errors.New("not found")
)

Error values

Functions

func UpdateTargetStatus added in v1.4.2

func UpdateTargetStatus(ctx context.Context, ds Datastore, targetID uuid.UUID, newStatus TargetStatus, description string) error

UpdateTargetStatus update datastore

Types

type Datastore

type Datastore interface {
	CreateTarget(ctx context.Context, target Target) error
	GetTarget(ctx context.Context, id uuid.UUID) (*Target, error)
	GetTargetByScope(ctx context.Context, scope string) (*Target, error)
	ListTargets(ctx context.Context) ([]Target, error)
	DeleteTarget(ctx context.Context, id uuid.UUID) error

	// Deprecated: Use datastore.UpdateTargetStatus.
	UpdateTargetStatus(ctx context.Context, targetID uuid.UUID, newStatus TargetStatus, description string) error
	UpdateToken(ctx context.Context, targetID uuid.UUID, newToken string, newExpiredAt time.Time) error

	UpdateTargetParam(ctx context.Context, targetID uuid.UUID, newResourceType ResourceType, newProviderURL sql.NullString) error

	EnqueueJob(ctx context.Context, job Job) error
	ListJobs(ctx context.Context) ([]Job, error)
	DeleteJob(ctx context.Context, id uuid.UUID) error

	CreateRunner(ctx context.Context, runner Runner) error
	ListRunners(ctx context.Context) ([]Runner, error)
	ListRunnersByTargetID(ctx context.Context, targetID uuid.UUID) ([]Runner, error)
	GetRunner(ctx context.Context, id uuid.UUID) (*Runner, error)
	DeleteRunner(ctx context.Context, id uuid.UUID, deletedAt time.Time, reason RunnerStatus) error

	// Lock
	GetLock(ctx context.Context) error
	IsLocked(ctx context.Context) (string, error)
}

Datastore is persistent storage

type Job

type Job struct {
	UUID           uuid.UUID      `db:"uuid"`
	GHEDomain      sql.NullString `db:"ghe_domain"`
	Repository     string         `db:"repository"` // repo (:owner/:repo)
	CheckEventJSON string         `db:"check_event"`
	TargetID       uuid.UUID      `db:"target_id"`
	CreatedAt      time.Time      `db:"created_at" json:"created_at"`
	UpdatedAt      time.Time      `db:"updated_at" json:"updated_at"`
}

Job is a runner job

func (*Job) RepoURL added in v1.9.5

func (j *Job) RepoURL() string

RepoURL return repository URL that send webhook.

type ResourceType

type ResourceType int

ResourceType is runner machine spec

const (
	ResourceTypeUnknown ResourceType = iota
	ResourceTypeNano
	ResourceTypeMicro
	ResourceTypeSmall
	ResourceTypeMedium
	ResourceTypeLarge
	ResourceTypeXLarge
	ResourceType2XLarge
	ResourceType3XLarge
	ResourceType4XLarge
)

ResourceTypes variables

func UnmarshalResourceType added in v1.2.1

func UnmarshalResourceType(src interface{}) ResourceType

UnmarshalResourceType cast type to ResourceType

func UnmarshalResourceTypePb added in v1.2.1

func UnmarshalResourceTypePb(in pb.ResourceType) ResourceType

UnmarshalResourceTypePb cast type from pb.ResourceType to ResourceType

func UnmarshalResourceTypeString added in v1.2.1

func UnmarshalResourceTypeString(in string) ResourceType

UnmarshalResourceTypeString cast type from string to ResourceType

func (ResourceType) MarshalJSON added in v1.4.1

func (r ResourceType) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding/json Marshaler interface

func (*ResourceType) Scan added in v1.2.1

func (r *ResourceType) Scan(src interface{}) error

Scan implements the database/sql Scanner interface

func (ResourceType) String

func (r ResourceType) String() string

String implement interface for fmt.Stringer

func (ResourceType) ToPb added in v1.2.0

func (r ResourceType) ToPb() pb.ResourceType

ToPb convert type of protobuf

func (*ResourceType) UnmarshalJSON added in v1.4.1

func (r *ResourceType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the encoding/json Unmarshaler interface

func (ResourceType) Value added in v1.2.1

func (r ResourceType) Value() (driver.Value, error)

Value implements the database/sql/driver Valuer interface

type Runner

type Runner struct {
	UUID           uuid.UUID      `db:"runner_id"`
	ShoesType      string         `db:"shoes_type"`
	IPAddress      string         `db:"ip_address"`
	TargetID       uuid.UUID      `db:"target_id"`
	CloudID        string         `db:"cloud_id"`
	Deleted        bool           `db:"deleted"`
	Status         RunnerStatus   `db:"status"`
	ResourceType   ResourceType   `db:"resource_type"`
	RunnerUser     sql.NullString `db:"runner_user" json:"runner_user"`
	ProviderURL    sql.NullString `db:"provider_url" json:"provider_url"`
	RepositoryURL  string         `db:"repository_url"`
	RequestWebhook string         `db:"request_webhook"`
	CreatedAt      time.Time      `db:"created_at"`
	UpdatedAt      time.Time      `db:"updated_at"`
	DeletedAt      sql.NullTime   `db:"deleted_at"`
}

Runner is a runner

type RunnerStatus added in v1.3.0

type RunnerStatus string

RunnerStatus is status for runner

type Target

type Target struct {
	UUID  uuid.UUID `db:"uuid" json:"id"`
	Scope string    `db:"scope" json:"scope"` // repo (:owner/:repo) or org (:organization)
	// deprecated
	GitHubToken    string         `db:"github_token" json:"github_token"`
	TokenExpiredAt time.Time      `db:"token_expired_at" json:"token_expired_at"`
	GHEDomain      sql.NullString `db:"ghe_domain" json:"ghe_domain"`

	ResourceType      ResourceType   `db:"resource_type" json:"resource_type"`
	ProviderURL       sql.NullString `db:"provider_url" json:"provider_url"`
	Status            TargetStatus   `db:"status" json:"status"`
	StatusDescription sql.NullString `db:"status_description" json:"status_description"`
	CreatedAt         time.Time      `db:"created_at" json:"created_at"`
	UpdatedAt         time.Time      `db:"updated_at" json:"updated_at"`
}

Target is a target repository that will add auto-scaling runner.

func ListTargets added in v1.6.2

func ListTargets(ctx context.Context, ds Datastore) ([]Target, error)

ListTargets get list of target that can receive job

func SearchRepo added in v1.15.1

func SearchRepo(ctx context.Context, ds Datastore, repo string) (*Target, error)

SearchRepo search datastore.Target from datastore format of repo is "orgs/repos"

func (*Target) CanReceiveJob added in v1.4.0

func (t *Target) CanReceiveJob() bool

CanReceiveJob check status in target

func (*Target) OwnerRepo

func (t *Target) OwnerRepo() (string, string)

OwnerRepo return :owner and :repo

type TargetStatus added in v1.3.0

type TargetStatus string

TargetStatus is status for target

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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