db

package
v0.0.0-...-a51c0b6 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssignUnassignedWorkParams

type AssignUnassignedWorkParams struct {
	Worker  uuid.NullUUID `json:"worker"`
	Column2 interface{}   `json:"column_2"`
}

type ChangeOccurenceStatusParams

type ChangeOccurenceStatusParams struct {
	Status Status `json:"status"`
	ID     int32  `json:"id"`
}

type CreateHistoryParams

type CreateHistoryParams struct {
	OccurenceID int32     `json:"occurence_id"`
	Schedule    uuid.UUID `json:"schedule"`
	Status      Status    `json:"status"`
	Details     string    `json:"details"`
	Manual      bool      `json:"manual"`
	ScheduledAt time.Time `json:"scheduled_at"`
	StartedAt   time.Time `json:"started_at"`
	CompletedAt time.Time `json:"completed_at"`
}

type CreateOccurenceParams

type CreateOccurenceParams struct {
	Schedule  uuid.UUID     `json:"schedule"`
	Worker    uuid.NullUUID `json:"worker"`
	Manual    bool          `json:"manual"`
	Status    Status        `json:"status"`
	Occurence sql.NullTime  `json:"occurence"`
}

type CreateScheduleParams

type CreateScheduleParams struct {
	ID     uuid.UUID `json:"id"`
	Cron   string    `json:"cron"`
	Hook   string    `json:"hook"`
	Owner  string    `json:"owner"`
	Active bool      `json:"active"`
	Till   time.Time `json:"till"`
	Data   string    `json:"data"`
}

type DBTX

type DBTX interface {
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	PrepareContext(context.Context, string) (*sql.Stmt, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}

type History

type History struct {
	OccurenceID int32     `json:"occurence_id"`
	Schedule    uuid.UUID `json:"schedule"`
	Status      Status    `json:"status"`
	Details     string    `json:"details"`
	Manual      bool      `json:"manual"`
	ScheduledAt time.Time `json:"scheduled_at"`
	StartedAt   time.Time `json:"started_at"`
	CompletedAt time.Time `json:"completed_at"`
}

type ListHistoryParams

type ListHistoryParams struct {
	Schedule uuid.UUID `json:"schedule"`
	Limit    int32     `json:"limit"`
	Offset   int32     `json:"offset"`
}

type ListHistoryRow

type ListHistoryRow struct {
	OccurenceID  int32     `json:"occurence_id"`
	Schedule     uuid.UUID `json:"schedule"`
	Status       Status    `json:"status"`
	Details      string    `json:"details"`
	Manual       bool      `json:"manual"`
	ScheduledAt  time.Time `json:"scheduled_at"`
	StartedAt    time.Time `json:"started_at"`
	CompletedAt  time.Time `json:"completed_at"`
	TotalRecords int64     `json:"-"`
}

type ListSchedulesParams

type ListSchedulesParams struct {
	Owner  string `json:"owner"`
	Limit  int32  `json:"limit"`
	Offset int32  `json:"offset"`
}

type ListSchedulesRow

type ListSchedulesRow struct {
	ID           uuid.UUID `json:"id"`
	Cron         string    `json:"cron"`
	Hook         string    `json:"hook"`
	Owner        string    `json:"owner"`
	Data         string    `json:"data"`
	Active       bool      `json:"active"`
	Till         time.Time `json:"till"`
	CreatedAt    time.Time `json:"created_at"`
	LastModified time.Time `json:"last_modified"`
	TotalRecords int64     `json:"total_records"`
}

type ListWorkersParams

type ListWorkersParams struct {
	Limit  int32 `json:"limit"`
	Offset int32 `json:"offset"`
}

type NextOccurence

type NextOccurence struct {
	ID          int32         `json:"id"`
	Schedule    uuid.UUID     `json:"schedule"`
	Worker      uuid.NullUUID `json:"worker"`
	Manual      bool          `json:"manual"`
	Status      Status        `json:"status"`
	Occurence   sql.NullTime  `json:"occurence"`
	LastUpdated time.Time     `json:"last_updated"`
}

type NullStatus

type NullStatus struct {
	Status Status
	Valid  bool // Valid is true if Status is not NULL
}

func (*NullStatus) Scan

func (ns *NullStatus) Scan(value interface{}) error

Scan implements the Scanner interface.

func (NullStatus) Value

func (ns NullStatus) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type PunchCard

type PunchCard struct {
	ID        uuid.UUID    `json:"id"`
	LastPunch time.Time    `json:"last_punch"`
	CreatedAt sql.NullTime `json:"created_at"`
}

type Querier

type Querier interface {
	AssignUnassignedWork(ctx context.Context, arg AssignUnassignedWorkParams) error
	ChangeOccurenceStatus(ctx context.Context, arg ChangeOccurenceStatusParams) error
	CreateHistory(ctx context.Context, arg CreateHistoryParams) (History, error)
	CreateOccurence(ctx context.Context, arg CreateOccurenceParams) (NextOccurence, error)
	CreateSchedule(ctx context.Context, arg CreateScheduleParams) (Schedule, error)
	CreateWorker(ctx context.Context, id uuid.UUID) (PunchCard, error)
	DeleteOccurence(ctx context.Context, id int32) error
	DeleteSchedule(ctx context.Context, id uuid.UUID) error
	DeleteWorker(ctx context.Context, id uuid.UUID) error
	GetNextImmediateWork(ctx context.Context, worker uuid.NullUUID) (time.Time, error)
	GetOccurence(ctx context.Context, id int32) (NextOccurence, error)
	GetSchedule(ctx context.Context, id uuid.UUID) (Schedule, error)
	GetWorker(ctx context.Context, id uuid.UUID) (PunchCard, error)
	ListHistory(ctx context.Context, arg ListHistoryParams) ([]ListHistoryRow, error)
	ListSchedules(ctx context.Context, arg ListSchedulesParams) ([]ListSchedulesRow, error)
	ListWorkers(ctx context.Context, arg ListWorkersParams) ([]PunchCard, error)
	MyExpiredWork(ctx context.Context, worker uuid.NullUUID) ([]NextOccurence, error)
	ProveLiveliness(ctx context.Context, id uuid.UUID) error
	RemoveDeadWorkers(ctx context.Context) error
	UpdateSchedule(ctx context.Context, arg UpdateScheduleParams) (Schedule, error)
	UpdateStatusAndDetails(ctx context.Context, arg UpdateStatusAndDetailsParams) (History, error)
	ValidSchedulesWithoutOccurence(ctx context.Context) ([]Schedule, error)
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) AssignUnassignedWork

func (q *Queries) AssignUnassignedWork(ctx context.Context, arg AssignUnassignedWorkParams) error

func (*Queries) ChangeOccurenceStatus

func (q *Queries) ChangeOccurenceStatus(ctx context.Context, arg ChangeOccurenceStatusParams) error

func (*Queries) CreateHistory

func (q *Queries) CreateHistory(ctx context.Context, arg CreateHistoryParams) (History, error)

func (*Queries) CreateOccurence

func (q *Queries) CreateOccurence(ctx context.Context, arg CreateOccurenceParams) (NextOccurence, error)

func (*Queries) CreateSchedule

func (q *Queries) CreateSchedule(ctx context.Context, arg CreateScheduleParams) (Schedule, error)

func (*Queries) CreateWorker

func (q *Queries) CreateWorker(ctx context.Context, id uuid.UUID) (PunchCard, error)

func (*Queries) DeleteOccurence

func (q *Queries) DeleteOccurence(ctx context.Context, id int32) error

func (*Queries) DeleteSchedule

func (q *Queries) DeleteSchedule(ctx context.Context, id uuid.UUID) error

func (*Queries) DeleteWorker

func (q *Queries) DeleteWorker(ctx context.Context, id uuid.UUID) error

func (*Queries) GetNextImmediateWork

func (q *Queries) GetNextImmediateWork(ctx context.Context, worker uuid.NullUUID) (time.Time, error)

func (*Queries) GetOccurence

func (q *Queries) GetOccurence(ctx context.Context, id int32) (NextOccurence, error)

func (*Queries) GetSchedule

func (q *Queries) GetSchedule(ctx context.Context, id uuid.UUID) (Schedule, error)

func (*Queries) GetWorker

func (q *Queries) GetWorker(ctx context.Context, id uuid.UUID) (PunchCard, error)

func (*Queries) ListHistory

func (q *Queries) ListHistory(ctx context.Context, arg ListHistoryParams) ([]ListHistoryRow, error)

func (*Queries) ListSchedules

func (q *Queries) ListSchedules(ctx context.Context, arg ListSchedulesParams) ([]ListSchedulesRow, error)

func (*Queries) ListWorkers

func (q *Queries) ListWorkers(ctx context.Context, arg ListWorkersParams) ([]PunchCard, error)

func (*Queries) MyExpiredWork

func (q *Queries) MyExpiredWork(ctx context.Context, worker uuid.NullUUID) ([]NextOccurence, error)

func (*Queries) ProveLiveliness

func (q *Queries) ProveLiveliness(ctx context.Context, id uuid.UUID) error

func (*Queries) RemoveDeadWorkers

func (q *Queries) RemoveDeadWorkers(ctx context.Context) error

func (*Queries) UpdateSchedule

func (q *Queries) UpdateSchedule(ctx context.Context, arg UpdateScheduleParams) (Schedule, error)

func (*Queries) UpdateStatusAndDetails

func (q *Queries) UpdateStatusAndDetails(ctx context.Context, arg UpdateStatusAndDetailsParams) (History, error)

func (*Queries) ValidSchedulesWithoutOccurence

func (q *Queries) ValidSchedulesWithoutOccurence(ctx context.Context) ([]Schedule, error)

func (*Queries) WithTx

func (q *Queries) WithTx(tx *sql.Tx) *Queries

type SQLStore

type SQLStore struct {
	*Queries
	// contains filtered or unexported fields
}

store provides all functions to execute db queries and transactions.

func (*SQLStore) Close

func (store *SQLStore) Close() error

func (*SQLStore) CreateScheduleAddNextOccurence

func (store *SQLStore) CreateScheduleAddNextOccurence(ctx context.Context, scheduleParams CreateScheduleParams, occurenceParams CreateOccurenceParams) (Schedule, error)

func (*SQLStore) UpdateHistoryAndDeleteOccurence

func (store *SQLStore) UpdateHistoryAndDeleteOccurence(ctx context.Context, params UpdateHistoryAndDeleteOccurenceParams) error

func (*SQLStore) UpdateHistoryAndOccurence

func (store *SQLStore) UpdateHistoryAndOccurence(ctx context.Context, schedule Schedule, occurence NextOccurence) error

type Schedule

type Schedule struct {
	ID     uuid.UUID `json:"id"`
	Cron   string    `json:"cron"`
	Hook   string    `json:"hook"`
	Owner  string    `json:"owner"`
	Data   string    `json:"data"`
	Active bool      `json:"active"`
	// till what timestamp this schedule will run
	Till         time.Time `json:"till"`
	CreatedAt    time.Time `json:"created_at"`
	LastModified time.Time `json:"last_modified"`
}

type Status

type Status string
const (
	StatusPending Status = "pending"
	StatusRunning Status = "running"
	StatusSuccess Status = "success"
	StatusFailure Status = "failure"
)

func (*Status) Scan

func (e *Status) Scan(src interface{}) error

type Store

type Store interface {
	Querier
	UpdateHistoryAndOccurence(ctx context.Context, schedule Schedule, occurence NextOccurence) error
	UpdateHistoryAndDeleteOccurence(ctx context.Context, params UpdateHistoryAndDeleteOccurenceParams) error
	CreateScheduleAddNextOccurence(ctx context.Context, schedule CreateScheduleParams, occurence CreateOccurenceParams) (Schedule, error)
	Close() error
}

func NewStore

func NewStore(db *sql.DB) Store

type UpdateHistoryAndDeleteOccurenceParams

type UpdateHistoryAndDeleteOccurenceParams struct {
	Schedule  Schedule
	Occurence NextOccurence
	Details   string
	Status    Status
}

type UpdateScheduleParams

type UpdateScheduleParams struct {
	ID     uuid.UUID `json:"id"`
	Cron   string    `json:"cron"`
	Hook   string    `json:"hook"`
	Active bool      `json:"active"`
	Till   time.Time `json:"till"`
	Data   string    `json:"data"`
}

type UpdateStatusAndDetailsParams

type UpdateStatusAndDetailsParams struct {
	OccurenceID int32  `json:"occurence_id"`
	Details     string `json:"details"`
	Status      Status `json:"status"`
}

Jump to

Keyboard shortcuts

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