Documentation
¶
Index ¶
- Constants
- func Custom(config Config, interceptors ...Interceptor)
- func Default(interceptors ...Interceptor)
- func Every(duration time.Duration, job JobItf)
- func GetEntries() []cron.Entry
- func GetEntry(id cron.EntryID) *cron.Entry
- func GetInfo() map[string]interface{}
- func GetStatusJSON() map[string]interface{}
- func New(interceptors ...Interceptor)
- func NewServer(address string) (*http.Server, error)
- func NewSideCarServer(commandCtrl *CommandController)
- func Remove(id cron.EntryID)
- func Schedule(spec string, job JobItf) error
- func ScheduleWithName(name, spec string, job JobItf) error
- func Schedules(spec, separator string, job JobItf) error
- func SetJobMetadata(ctx context.Context, meta JobMetadata) context.Context
- func Stop()
- type CommandController
- type Config
- type Func
- type Handler
- type Interceptor
- type Job
- type JobItf
- type JobMetadata
- type ServerController
- type StatusCode
- type StatusData
Constants ¶
const (
// CtxKeyJobMetadata is context for cron job metadata.
CtxKeyJobMetadata = contextKey("cron-job-metadata")
)
Context key for standardized context value.
const SleepDuration = time.Second * 10
SleepDuration defines the duration to sleep the server if the defined address is busy.
Variables ¶
This section is empty.
Functions ¶
func Custom ¶ added in v0.2.0
func Custom(config Config, interceptors ...Interceptor)
Custom creates a cron with custom config. For advance user, allow custom modification.
func Default ¶
func Default(interceptors ...Interceptor)
Default creates a cron with default config. HTTP server is built in as side car by default.
func Every ¶
Every executes the given job at a fixed interval. The interval provided is the time between the job ending and the job being run again. The time that the job takes to run is not included in the interval. Minimal time is 1 sec.
func GetEntries ¶
func GetEntries() []cron.Entry
GetEntries returns all the current registered jobs.
func GetEntry ¶
func GetEntry(id cron.EntryID) *cron.Entry
GetEntry returns a snapshot of the given entry, or nil if it couldn't be found.
func GetInfo ¶
func GetInfo() map[string]interface{}
GetInfo returns current cron check basic information.
func GetStatusJSON ¶
func GetStatusJSON() map[string]interface{}
GetStatusJSON returns all jobs status as map[string]interface.
func NewServer ¶
NewServer creates a new HTTP server. - / => current server status. - /jobs => current jobs as frontend html. - /api/jobs => current jobs as json.
func NewSideCarServer ¶ added in v0.2.0
func NewSideCarServer(commandCtrl *CommandController)
NewSideCarServer creates a new side car HTTP server. HTTP server will be start automatically. - / => current server status. - /jobs => current jobs as frontend html. - /api/jobs => current jobs as json.
func Remove ¶
func Remove(id cron.EntryID)
Remove removes a specific job from running. Get EntryID from the list job entries cronx.GetEntries(). If job is in the middle of running, once the process is finished it will be removed.
func Schedule ¶
Schedule sets a job to run at specific time. Example:
@every 5m 0 */10 * * * * => every 10m
func ScheduleWithName ¶ added in v0.2.0
ScheduleWithName sets a job to run at specific time with a Job name Example:
@every 5m 0 */10 * * * * => every 10m
func Schedules ¶
Schedules sets a job to run multiple times at specific time. Symbol */,-? should never be used as separator character. These symbols are reserved for cron specification.
Example:
Spec : "0 0 1 * * *#0 0 2 * * *#0 0 3 * * * Separator : "#" This input schedules the job to run 3 times.
func SetJobMetadata ¶
func SetJobMetadata(ctx context.Context, meta JobMetadata) context.Context
SetJobMetadata stores current job metadata inside current context.
Types ¶
type CommandController ¶
type CommandController struct { // Commander holds all the underlying cron jobs. Commander *cron.Cron // Interceptor holds middleware that will be executed before current job operation. Interceptor Interceptor // Parser is a custom parser to support v1 that contains second as first parameter. Parser cron.Parser // UnregisteredJobs describes the list of jobs that have been failed to be registered. UnregisteredJobs []*Job // Address determines the address will we serve the json and frontend status. // Empty string meaning we won't serve the current job status. Address string // Location describes the timezone current cron is running. // By default the timezone will be the same timezone as the server. Location *time.Location // CreatedTime describes when the command controller created. CreatedTime time.Time }
CommandController controls all the underlying job.
func NewCommandController ¶
func NewCommandController(config Config, interceptors ...Interceptor) *CommandController
NewCommandController create a command controller with a specific config.
func (*CommandController) Info ¶
func (c *CommandController) Info() map[string]interface{}
Info returns command controller basic information.
func (*CommandController) StatusData ¶
func (c *CommandController) StatusData() []StatusData
StatusData returns all jobs status.
func (*CommandController) StatusJSON ¶
func (c *CommandController) StatusJSON() map[string]interface{}
StatusJSON returns all jobs status as map[string]interface.
type Config ¶
type Config struct { // Address determines the address will we serve the json and frontend status. // Empty string meaning we won't serve the current job status. Address string // Location describes the timezone current cron is running. Location *time.Location }
Config defines the config for the command controller.
type Func ¶
Func is a type to allow callers to wrap a raw func. Example:
cronx.Schedule("@every 5m", cronx.Func(myFunc))
type Interceptor ¶
Interceptor is the middleware that will be executed before the current handler.
func Chain ¶
func Chain(interceptors ...Interceptor) Interceptor
Chain returns a single interceptor from multiple interceptors.
type Job ¶
type Job struct { JobMetadata Name string `json:"name"` Status StatusCode `json:"status"` Latency string `json:"latency"` Error string `json:"error"` // contains filtered or unexported fields }
func (*Job) UpdateStatus ¶
func (j *Job) UpdateStatus() StatusCode
UpdateStatus updates the current job status to the latest.
type JobMetadata ¶
type JobMetadata struct { EntryID cron.EntryID `json:"entry_id"` Wave int64 `json:"wave"` TotalWave int64 `json:"total_wave"` IsLastWave bool `json:"is_last_wave"` }
func GetJobMetadata ¶
func GetJobMetadata(ctx context.Context) (JobMetadata, bool)
GetJobMetadata returns job metadata from current context, and status if it exists or not.
type ServerController ¶
type ServerController struct { // CommandController controls all the underlying job. CommandController *CommandController }
ServerController is http server controller.
func (*ServerController) APIJobs ¶
func (c *ServerController) APIJobs(ctx echo.Context) error
APIJobs returns job status as json.
func (*ServerController) HealthCheck ¶
func (c *ServerController) HealthCheck(ctx echo.Context) error
HealthCheck returns server status.
func (*ServerController) Jobs ¶
func (c *ServerController) Jobs(ctx echo.Context) error
Jobs return job status as frontend template.
type StatusCode ¶
type StatusCode string
StatusCode describes current job status.
const ( // StatusCodeUp describes that current job has just been created. StatusCodeUp StatusCode = "UP" // StatusCodeIdle describes that current job is waiting for next execution time. StatusCodeIdle StatusCode = "IDLE" // StatusCodeRunning describes that current job is currently running. StatusCodeRunning StatusCode = "RUNNING" // StatusCodeDown describes that current job has failed to be registered. StatusCodeDown StatusCode = "DOWN" // StatusCodeError describes that last run has failed. StatusCodeError StatusCode = "ERROR" )
type StatusData ¶
type StatusData struct { // ID is unique per job. ID cron.EntryID `json:"id,omitempty"` // Job defines current job. Job *Job `json:"job,omitempty"` // Next defines the next schedule to execute current job. Next time.Time `json:"next_run,omitempty"` // Prev defines the last run of the current job. Prev time.Time `json:"prev_run,omitempty"` }
StatusData defines current job status.