cheek

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusOK    int = 0
	StatusError int = -1
)

Global status constants

Variables

View Source
var Version = "development"

Version will be set through build flags used to print version via cmd.

Functions

func CheekPath

func CheekPath() string

func InitDB

func InitDB(db *sqlx.DB) error

func NewDBLogWriter

func NewDBLogWriter(db *sqlx.DB) io.Writer

func NewDefaultWebhook

func NewDefaultWebhook(endpoint string) defaultWebhook

func NewDiscordWebhook

func NewDiscordWebhook(endpoint string) discordWebhook

func NewLogger

func NewLogger(logLevel string, db *sqlx.DB, extraWriters ...io.Writer) zerolog.Logger

Configures the package's global logger, also allows to pass in custom writers for testing purposes.

func NewSlackWebhook

func NewSlackWebhook(endpoint string) slackWebhook

func OpenDB

func OpenDB(dbPath string) (*sqlx.DB, error)

func PrettyStdout

func PrettyStdout() io.Writer

func RunSchedule

func RunSchedule(log zerolog.Logger, cfg Config, scheduleFn string) error

RunSchedule is the main entry entrypoint of cheek.

Types

type Config

type Config struct {
	Pretty       bool   `yaml:"pretty"`
	SuppressLogs bool   `yaml:"suppressLogs"`
	LogLevel     string `yaml:"logLevel"`
	HomeDir      string `yaml:"homedir"`
	Port         string `yaml:"port"`
	DBPath       string `yaml:"dbpath"`
	DB           *sqlx.DB
}

func NewConfig

func NewConfig() Config

func (*Config) Init

func (c *Config) Init() error

type DBLogWriter

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

func (DBLogWriter) Write

func (w DBLogWriter) Write(p []byte) (n int, err error)

type JobRun

type JobRun struct {
	LogEntryId int  `json:"id,omitempty" db:"id"`
	Status     *int `json:"status,omitempty" db:"status,omitempty"`

	Log               string        `json:"log" db:"message"`
	Name              string        `json:"name" db:"job"`
	TriggeredAt       time.Time     `json:"triggered_at" db:"triggered_at"`
	TriggeredBy       string        `json:"triggered_by" db:"triggered_by,omitempty"`
	TriggeredByJobRun *JobRun       `json:"triggered_by_job_run,omitempty"`
	Triggered         []string      `json:"triggered,omitempty"`
	Duration          time.Duration `json:"duration,omitempty" db:"duration"`
	RetryAttempt      int           `json:"retry_attempt,omitempty"`
	RetriesExhausted  bool          `json:"retries_exhausted,omitempty"`
	// contains filtered or unexported fields
}

JobRun holds information about a job execution.

func RunJob

func RunJob(log zerolog.Logger, cfg Config, scheduleFn string, jobName string) (JobRun, error)

RunJob allows to run a specific job

type JobSpec

type JobSpec struct {
	Yaml string `yaml:"-" json:"yaml,omitempty"`

	Cron    string      `yaml:"cron,omitempty" json:"cron,omitempty"`
	Command stringArray `yaml:"command" json:"command"`

	OnSuccess          OnEvent `yaml:"on_success,omitempty" json:"on_success,omitempty"`
	OnError            OnEvent `yaml:"on_error,omitempty" json:"on_error,omitempty"`
	OnRetriesExhausted OnEvent `yaml:"on_retries_exhausted,omitempty" json:"on_retries_exhausted,omitempty"`

	Name                       string            `json:"name"`
	Retries                    int               `yaml:"retries,omitempty" json:"retries,omitempty"`
	Env                        map[string]secret `yaml:"env,omitempty"`
	WorkingDirectory           string            `yaml:"working_directory,omitempty" json:"working_directory,omitempty"`
	DisableConcurrentExecution bool              `yaml:"disable_concurrent_execution,omitempty" json:"disable_concurrent_execution,omitempty"`

	Runs []JobRun `json:"runs" yaml:"-"`
	// contains filtered or unexported fields
}

JobSpec holds specifications and metadata of a job.

func (*JobSpec) OnEvent

func (j *JobSpec) OnEvent(jr *JobRun)

func (*JobSpec) OnRetriesExhaustedEvent

func (j *JobSpec) OnRetriesExhaustedEvent(jr *JobRun)

func (*JobSpec) ToYAML

func (j *JobSpec) ToYAML(includeRuns bool) (string, error)

func (*JobSpec) ValidateCron

func (j *JobSpec) ValidateCron() error

type OnEvent

type OnEvent struct {
	TriggerJob           []string `yaml:"trigger_job,omitempty" json:"trigger_job,omitempty"`
	NotifyWebhook        []string `yaml:"notify_webhook,omitempty" json:"notify_webhook,omitempty"`
	NotifySlackWebhook   []string `yaml:"notify_slack_webhook,omitempty" json:"notify_slack_webhook,omitempty"`
	NotifyDiscordWebhook []string `yaml:"notify_discord_webhook,omitempty" json:"notify_discord_webhook,omitempty"`
}

OnEvent contains specs on what needs to happen after a job event.

type Response

type Response struct {
	Job    string `json:"jobs,omitempty"`
	Status string `json:"status,omitempty"`
	Type   string `json:"type,omitempty"`
}

type Schedule

type Schedule struct {
	Jobs               map[string]*JobSpec `yaml:"jobs" json:"jobs"`
	OnSuccess          OnEvent             `yaml:"on_success,omitempty" json:"on_success,omitempty"`
	OnError            OnEvent             `yaml:"on_error,omitempty" json:"on_error,omitempty"`
	OnRetriesExhausted OnEvent             `yaml:"on_retries_exhausted,omitempty" json:"on_retries_exhausted,omitempty"`
	TZLocation         string              `yaml:"tz_location,omitempty" json:"tz_location,omitempty"`
	// contains filtered or unexported fields
}

Schedule defines specs of a job schedule.

func (*Schedule) Run

func (s *Schedule) Run()

type ScheduleStatusResponse

type ScheduleStatusResponse struct {
	Status         map[string]int `json:"status,omitempty"`
	FailedRunCount int            `json:"failed_run_count,omitempty"`
	HasFailedRuns  bool           `json:"has_failed_runs,omitempty"`
}

type TemplateData

type TemplateData struct {
	Name string
}

type VersionResponse

type VersionResponse struct {
	Version   string `json:"version"`
	CommitSHA string `json:"commit_sha"`
}

Jump to

Keyboard shortcuts

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