CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/golang-github-com-go-co-op-gocron-v2

A Golang job scheduling library that lets you run Go functions at pre-determined intervals using cron expressions, fixed durations, daily, weekly, monthly, or one-time schedules with support for distributed deployments.

Overview
Eval results
Files

types.mddocs/guides/api/

API Reference: Types

Quick reference for core types and interfaces.

Core Types

Scheduler

type Scheduler interface {
    Start()
    Shutdown() error
    NewJob(JobDefinition, Task, ...JobOption) (Job, error)
    Update(uuid.UUID, JobDefinition, Task, ...JobOption) (Job, error)
    RemoveJob(uuid.UUID) error
    RemoveByTags(...string) error
    Jobs() []Job
    JobsWaitingInQueue() int
}

See Scheduler API

Job

type Job interface {
    ID() uuid.UUID
    Name() string
    Tags() []string
    NextRun() (time.Time, error)
    LastRun() (time.Time, error)
    RunNow() error
}

Task

type Task interface {
    // Internal interface
}

// Create with:
task := gocron.NewTask(func() {
    // work
})

See Tasks API

LimitMode

type LimitMode int

const (
    LimitModeReschedule LimitMode = 1
    LimitModeWait       LimitMode = 2
)

Job Definitions

DurationJob

gocron.DurationJob(5*time.Minute)
gocron.DurationRandomJob(time.Minute, 5*time.Minute)

See Duration Jobs API

CronJob

gocron.CronJob("*/5 * * * *", false)
gocron.CronJob("TZ=America/New_York 0 9 * * *", false)

See Cron Jobs API

Time-Based Jobs

gocron.DailyJob(1, gocron.NewAtTimes(gocron.NewAtTime(9, 0, 0)))
gocron.WeeklyJob(1, gocron.NewWeekdays(time.Monday), gocron.NewAtTimes(...))
gocron.MonthlyJob(1, gocron.NewDaysOfTheMonth(1, 15), gocron.NewAtTimes(...))

See Time-Based Jobs API

OneTimeJob

gocron.OneTimeJob(
    gocron.OneTimeJobStartDateTime(time.Now().Add(time.Hour)),
)

See One-Time Jobs API

Monitor Interfaces

Logger

type Logger interface {
    Debug(msg string, args ...any)
    Error(msg string, args ...any)
    Info(msg string, args ...any)
    Warn(msg string, args ...any)
}

Monitor

type Monitor interface {
    RecordJobTiming(
        start time.Time,
        duration time.Duration,
        jobID uuid.UUID,
        jobName string,
        tags []string,
    )
}

SchedulerMonitor

type SchedulerMonitor interface {
    JobScheduled(jobID uuid.UUID, job Job)
    JobUnscheduled(jobID uuid.UUID, job Job)
    JobStarted(jobID uuid.UUID, job Job)
    JobCompleted(jobID uuid.UUID, job Job, err error)
    ConcurrencyLimitReached(limitType string, job Job)
}

See Monitoring Types API

Distributed Interfaces

Elector

type Elector interface {
    IsLeader(context.Context) error
}

Locker

type Locker interface {
    Lock(context.Context, string) (Lock, error)
}

type Lock interface {
    Unlock(context.Context) error
}

See Distributed Types API

See Also

Install with Tessl CLI

npx tessl i tessl/golang-github-com-go-co-op-gocron-v2

docs

index.md

tile.json