kronk

package module
v0.0.0-...-4d7a4a1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2022 License: MIT Imports: 6 Imported by: 0

README

kronk GoDoc

kronk is dead simple scheduler for modern scalable systems.

It allows you to manage background tasks in a distributed architecture.

Already supports Redis as distributed lock manager.

So, now you can add jobs and be sure that they will be completed on only one instance.

Get started

1. Install and import package

go get -u github.com/utkonos-dev/kronk

2. Create Kronk
import (
    "github.com/utkonos-dev/kronk"
    redisAdapter "github.com/utkonos-dev/kronk/dlm/redis"
    "github.com/utkonos-dev/kronk/scheduler/cron"
)
k := kronk.New(
    redisAdapter.NewLocker(redisConn),
    cron.NewScheduler(),
    logger,
    kronk.Config{
        DefaultLockExp:     time.Second,
    },
)
3. Start scheduler
k.Start()
4. Add job

AddJob can be safely called on all instances, but the job will be performed only by one.

job := func() {
    fmt.Println("That'll work")
}

err := k.AddRegularJob("kronksays", "* * * * *", job)
if err != nil {
    // ...
}

PR accepted!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrJobNotFound = errors.New("job not found")
	ErrExpiredJob  = errors.New("expired job")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	DefaultLockExp time.Duration
	SkipDuplicate  bool
}

type Kronk

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

func New

func New(locker dlm.DLM, scheduler scheduler.Scheduler, logger Logger, cfg Config) *Kronk

func (*Kronk) AddOneTimeJob

func (k *Kronk) AddOneTimeJob(name string, runAt time.Time, job func()) error

func (*Kronk) AddRegularJob

func (k *Kronk) AddRegularJob(name, cronTab string, job func()) error

func (*Kronk) RemoveJob

func (k *Kronk) RemoveJob(name string) error

func (*Kronk) Scheduler

func (k *Kronk) Scheduler() scheduler.Scheduler

func (*Kronk) Start

func (k *Kronk) Start()

type Logger

type Logger interface {
	Println(v ...interface{})
	Printf(format string, v ...interface{})
}

Directories

Path Synopsis
dlm

Jump to

Keyboard shortcuts

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