schedule

package
v0.0.0-...-8fd811e Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeCommand = "command"
	TypeScript  = "script"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base struct {
	ID        string    `json:"id" db:"id"`
	CreatedAt time.Time `json:"created_at" db:"created_at"`
	CreatedBy string    `json:"created_by" db:"created_by"`
	Name      string    `json:"name" db:"name"`
	Schedule  string    `json:"schedule" db:"schedule"`
	Type      string    `json:"type" db:"type"`
}

type Cron

type Cron interface {
	Validate(string) error
	Add(string, string, func(context.Context, string)) error
	Remove(string)
}

type CronImplementation

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

func (*CronImplementation) Add

func (c *CronImplementation) Add(id string, schedule string, f func(context.Context, string)) error

func (*CronImplementation) Remove

func (c *CronImplementation) Remove(id string)

func (*CronImplementation) Validate

func (c *CronImplementation) Validate(schedule string) error

type DBSchedule

type DBSchedule struct {
	Base
	Details Details `db:"details"`
	Execution
}

DBSchedule is used for saving to database and has details in one json db column

func (DBSchedule) ToSchedule

func (dbs DBSchedule) ToSchedule() *Schedule

type Details

type Details struct {
	ClientIDs           []string              `json:"client_ids" db:"-"`
	GroupIDs            []string              `json:"group_ids" db:"-"`
	ClientTags          *models.JobClientTags `json:"tags" db:"-"`
	Command             string                `json:"command,omitempty" db:"-"`
	Script              string                `json:"script,omitempty" db:"-"`
	Interpreter         string                `json:"interpreter" db:"-"`
	Cwd                 string                `json:"cwd" db:"-"`
	IsSudo              bool                  `json:"is_sudo" db:"-"`
	TimeoutSec          int                   `json:"timeout_sec" db:"-"`
	ExecuteConcurrently bool                  `json:"execute_concurrently" db:"-"`
	AbortOnError        *bool                 `json:"abort_on_error" db:"-"`
	Overlaps            bool                  `json:"overlaps" db:"-"`
}

func (*Details) Scan

func (d *Details) Scan(value interface{}) error

func (Details) Value

func (d Details) Value() (driver.Value, error)

type Execution

type Execution struct {
	StartedAt    *time.Time `db:"last_started_at" json:"started_at"`
	ClientCount  *int       `db:"last_client_count" json:"client_count"`
	SuccessCount *int       `db:"last_success_count" json:"success_count"`
	Status       *string    `db:"last_status" json:"status"`

	Details *jobs.JobDetails `db:"last_details" json:"-"`
	Summary *string          `json:"summary"`
}

All fields must be pointers, because when there's no execution yet the values will be nil

func (*Execution) ToLastExecution

func (e *Execution) ToLastExecution() *Execution

type JobRunner

type JobRunner interface {
	StartMultiClientJob(ctx context.Context, multiJobRequest *jobs.MultiJobRequest) (*models.MultiJob, error)
}

type Manager

type Manager struct {
	*logger.Logger
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, logger *logger.Logger, db *sqlx.DB, jobRunner JobRunner, runRemoteCmdTimeoutSec int) (*Manager, error)

func NewManager

func NewManager(jobRunner JobRunner, db *sqlx.DB, logger *logger.Logger, runRemoteCmdTimeoutSec int) (m *Manager)

func (*Manager) Create

func (m *Manager) Create(ctx context.Context, s *Schedule, user string) (*Schedule, error)

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context, id string) error

func (*Manager) Get

func (m *Manager) Get(ctx context.Context, id string) (*Schedule, error)

func (*Manager) List

func (m *Manager) List(ctx context.Context, r *http.Request) (*api.SuccessPayload, error)

func (*Manager) Update

func (m *Manager) Update(ctx context.Context, id string, s *Schedule) (*Schedule, error)

type Provider

type Provider interface {
	Insert(context.Context, *Schedule) error
	Update(context.Context, *Schedule) error
	List(context.Context, *query.ListOptions) ([]*Schedule, error)
	Get(context.Context, string) (*Schedule, error)
	Delete(context.Context, string) error
	CountJobsInProgress(ctx context.Context, scheduleID string, timeoutSec int) (int, error)
}

type SQLiteProvider

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

func (*SQLiteProvider) Close

func (p *SQLiteProvider) Close() error

func (*SQLiteProvider) CountJobsInProgress

func (p *SQLiteProvider) CountJobsInProgress(ctx context.Context, scheduleID string, timeoutSec int) (int, error)

CountJobsInProgress counts jobs for scheduleID that have not finished and are not timed out

func (*SQLiteProvider) Delete

func (p *SQLiteProvider) Delete(ctx context.Context, id string) error

func (*SQLiteProvider) Get

func (p *SQLiteProvider) Get(ctx context.Context, id string) (*Schedule, error)

func (*SQLiteProvider) Insert

func (p *SQLiteProvider) Insert(ctx context.Context, s *Schedule) error

func (*SQLiteProvider) List

func (p *SQLiteProvider) List(ctx context.Context, options *query.ListOptions) ([]*Schedule, error)

func (*SQLiteProvider) Update

func (p *SQLiteProvider) Update(ctx context.Context, s *Schedule) error

type Schedule

type Schedule struct {
	Base
	Details
	LastExecution *Execution `json:"last_execution"`
}

func (*Schedule) GetClientIDs

func (s *Schedule) GetClientIDs() (ids []string)

func (*Schedule) GetClientTags

func (s *Schedule) GetClientTags() (clientTags *models.JobClientTags)

func (*Schedule) GetGroupIDs

func (s *Schedule) GetGroupIDs() (ids []string)

func (Schedule) ToDB

func (s Schedule) ToDB() DBSchedule

Jump to

Keyboard shortcuts

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