scheduler

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultCronField = "cron"
View Source
const DefaultIdField = "id"
View Source
const DefaultIsActiveField = "is_active"
View Source
const DefaultLastRunAtField = "last_run_at"
View Source
const DefaultNameField = "name"
View Source
const DefaultNextRunAtField = "next_run_at"
View Source
const DefaultPayloadField = "payload"
View Source
const DefaultTableName = "barn_schedule"

Variables

This section is empty.

Functions

This section is empty.

Types

type PostgresSchedulerRepository

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

func (*PostgresSchedulerRepository) Create

func (r *PostgresSchedulerRepository) Create(tx *sql.Tx, s *Schedule) error

func (*PostgresSchedulerRepository) CreateTable

func (r *PostgresSchedulerRepository) CreateTable(tx *sql.Tx) error

func (*PostgresSchedulerRepository) Delete

func (r *PostgresSchedulerRepository) Delete(tx *sql.Tx, pk int) error

func (*PostgresSchedulerRepository) DeleteAll

func (r *PostgresSchedulerRepository) DeleteAll(tx *sql.Tx) error

func (*PostgresSchedulerRepository) FindAllActive

func (r *PostgresSchedulerRepository) FindAllActive(tx *sql.Tx) ([]*Schedule, error)

func (*PostgresSchedulerRepository) FindAllActiveAndUnprocessed added in v0.2.3

func (r *PostgresSchedulerRepository) FindAllActiveAndUnprocessed(tx *sql.Tx, moment time.Time) ([]*Schedule, error)

func (*PostgresSchedulerRepository) FindOne

func (r *PostgresSchedulerRepository) FindOne(tx *sql.Tx, pk int) (*Schedule, error)

func (*PostgresSchedulerRepository) Save

func (r *PostgresSchedulerRepository) Save(tx *sql.Tx, s *Schedule) error

type Schedule

type Schedule struct {
	Id        int
	Name      string
	IsActive  bool
	Cron      *string
	NextRunAt *time.Time
	LastRunAt *time.Time
	Payload   any
}

func (Schedule) LogValue

func (e Schedule) LogValue() slog.Value

type ScheduleQueryConfig

type ScheduleQueryConfig struct {
	TableName      string
	IdField        string
	NameField      string
	IsActiveField  string
	CronField      string
	NextRunAtField string
	LastRunAtField string
	PayloadField   string
}

type Scheduler

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

func NewScheduler

func NewScheduler(db *sql.DB, config *SchedulerConfig) *Scheduler

func (*Scheduler) Start

func (s *Scheduler) Start()

func (*Scheduler) StartContext

func (s *Scheduler) StartContext(ctx context.Context)

func (*Scheduler) Stop

func (s *Scheduler) Stop()

type SchedulerConfig

type SchedulerConfig struct {
	Log        *slog.Logger
	Repository SchedulerRepository
	ReloadCron string
	Handler    SchedulerHandler
}

type SchedulerHandler

type SchedulerHandler func(tx *sql.Tx, schedule *Schedule) error

type SchedulerRepository

type SchedulerRepository interface {
	FindAllActive(tx *sql.Tx) ([]*Schedule, error)
	FindOne(tx *sql.Tx, pk int) (*Schedule, error)
	Save(tx *sql.Tx, s *Schedule) error
	Delete(tx *sql.Tx, pk int) error
}

func NewPostgresSchedulerRepository added in v0.2.0

func NewPostgresSchedulerRepository(config ...ScheduleQueryConfig) SchedulerRepository

type SimpleScheduler

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

func NewSimpleScheduler

func NewSimpleScheduler(db *sql.DB, config *SimpleSchedulerConfig) *SimpleScheduler

func (*SimpleScheduler) Start

func (s *SimpleScheduler) Start()

func (*SimpleScheduler) StartContext

func (s *SimpleScheduler) StartContext(ctx context.Context)

func (*SimpleScheduler) Stop

func (s *SimpleScheduler) Stop()

type SimpleSchedulerConfig

type SimpleSchedulerConfig struct {
	Log        *slog.Logger
	Repository SimpleSchedulerRepository
	Cron       string
	Handler    SchedulerHandler
}

type SimpleSchedulerRepository added in v0.2.3

type SimpleSchedulerRepository interface {
	FindAllActiveAndUnprocessed(tx *sql.Tx, moment time.Time) ([]*Schedule, error)
	FindOne(tx *sql.Tx, pk int) (*Schedule, error)
	Save(tx *sql.Tx, s *Schedule) error
	Delete(tx *sql.Tx, pk int) error
}

func NewPostgresSimpleSchedulerRepository added in v0.2.3

func NewPostgresSimpleSchedulerRepository(config ...ScheduleQueryConfig) SimpleSchedulerRepository

Jump to

Keyboard shortcuts

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