storage

package
v0.0.0-...-93a69da Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignJobsToPartition

func AssignJobsToPartition(ctx context.Context, db IDB, target int, limit int) error

func GetScheduledJob

func GetScheduledJob(ctx context.Context, db IDB, id string, userId int64) (entities.ScheduledJob, error)

func GetUserByApiKey

func GetUserByApiKey(ctx context.Context, db IDB, apiKey string) (entities.User, error)

func GetUserByUserName

func GetUserByUserName(ctx context.Context, db IDB, username string) (entities.User, error)

func InsertExecution

func InsertExecution(ctx context.Context, db IDB, job entities.Execution) (entities.Execution, error)

func InsertScheduledJob

func InsertScheduledJob(ctx context.Context, db IDB, job entities.ScheduledJob) (entities.ScheduledJob, error)

func InsertUser

func InsertUser(ctx context.Context, db IDB, u entities.User) (entities.User, error)

func Notify

func Notify(ctx context.Context, db IDB, payload any) error

func ReBalance

func ReBalance(ctx context.Context, db IDB, active []int) error

func RemovesJobsFromPartition

func RemovesJobsFromPartition(ctx context.Context, db IDB, current int, limit int) error

func SelectExecutions

func SelectExecutions(ctx context.Context, db IDB, jobID int64) ([]entities.Execution, error)

func SelectJobsForExecution

func SelectJobsForExecution(ctx context.Context, db *DB, partition int, limit int, now time.Time) ([]entities.ScheduledJob, entities.ScheduledJob, error)

func ToEntitiesExecution

func ToEntitiesExecution(e Execution) entities.Execution

func ToEntitiesUser

func ToEntitiesUser(u User) entities.User

func ToScheduledJobEntity

func ToScheduledJobEntity(j ScheduledJob) entities.ScheduledJob

func UpdateJobStatus

func UpdateJobStatus(ctx context.Context, db IDB, job entities.ScheduledJob) error

func UpdateJobsPartitions

func UpdateJobsPartitions(ctx context.Context, db IDB, active []int, target int) error

func UpdateScheduledJobsPartitions

func UpdateScheduledJobsPartitions(ctx context.Context, db IDB, job entities.ScheduledJob) error

func UserExists

func UserExists(ctx context.Context, db IDB, username string) (bool, error)

Types

type DB

type DB struct {
	*bun.DB
	// contains filtered or unexported fields
}

func New

func New(cfg DbConfig) (*DB, error)

func (*DB) Close

func (o *DB) Close() error

func (*DB) Listen

func (o *DB) Listen(ctx context.Context, outc chan<- struct{}, p int) error

type DbConfig

type DbConfig struct {
	DSN          string
	MaxOpenConns int
	Debug        bool
	PgDriver     bool
}

type Execution

type Execution struct {
	bun.BaseModel

	ID             int64 `bun:"id,pk,autoincrement"`
	ScheduledJobID int64 `bun:"scheduled_job_id"`
	StatusCode     int
	Msg            string
	CreatedAt      time.Time
}

func FromEntitiesExecution

func FromEntitiesExecution(e entities.Execution) Execution

type IDB

type IDB = bun.IDB

type ScheduledJob

type ScheduledJob struct {
	bun.BaseModel

	ID          int64 `bun:"id,pk,autoincrement"`
	UID         uuid.UUID
	UserID      int64
	Name        string
	Description string
	Url         string
	Payload     string
	ContentType string
	Signature   string
	RunAt       time.Time
	Retries     int
	Status      int
	Partition   int
	CreatedAt   time.Time
	UpdatedAt   bun.NullTime
}

func FromScheduledJobEntity

func FromScheduledJobEntity(j entities.ScheduledJob) ScheduledJob

type User

type User struct {
	bun.BaseModel

	ID        int64
	Username  string
	ApiKey    *string
	CreatedAt time.Time
}

func FromEntitiesUser

func FromEntitiesUser(u entities.User) User

Jump to

Keyboard shortcuts

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