clockwork

package module
v0.0.0-...-027e62a Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2020 License: MIT Imports: 5 Imported by: 5

README

clockwork

Awesome GoDoc Go Report Card Coverage

A simple and intuitive scheduling library in Go.

Inspired by python's schedule and ruby's clockwork libraries.

Example use

package main

import (
	"fmt"
	"github.com/whiteshtef/clockwork"
)

func main() {
	sched := clockwork.NewScheduler()

	sched.Schedule().Every(10).Seconds().Do(something)
	sched.Schedule().Every(3).Minutes().Do(something)
	sched.Schedule().Every(4).Hours().Do(something)
	sched.Schedule().Every(2).Days().At("12:32").Do(something)
	sched.Schedule().Every(12).Weeks().Do(something)

	sched.Schedule().Every().Second().Do(something) // Every() is "shorthand" for Every(1)
	sched.Schedule().Every().Monday().Do(something)
	sched.Schedule().Every().Saturday().At("8:00").Do(something)

	sched.Run()
}

func something() {
	fmt.Println("foo")

}

The package uses go dep for dependency management.

Documentation

Overview

Package clockwork enables simple and intuitive scheduling in Go.

Examples:

sched.Schedule().Every(10).Seconds().Do(something)
sched.Schedule().Every(3).Minutes().Do(something)
sched.Schedule().Every(4).Hours().Do(something)
sched.Schedule().Every(2).Days().At("12:32").Do(something)
sched.Schedule().Every(12).Weeks().Do(something)
sched.Schedule().Every(1).Monday().Do(something)
sched.Schedule().Every(1).Saturday().At("8:00").Do(something)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

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

Job struct handles all the data required to schedule and run jobs.

func (*Job) At

func (j *Job) At(t string) *Job

At method fills the given Job struct atHour and atMinute fields with the provided information

func (*Job) Day

func (j *Job) Day() *Job

Day method fills the given job struct with days

func (*Job) Days

func (j *Job) Days() *Job

Days method fills the given job struct with days

func (*Job) Do

func (j *Job) Do(function func()) string

Do method fills the given job struct with the function pointer to the job (user provided task) itself.

func (*Job) Every

func (j *Job) Every(frequencies ...int) *Job

Every is a method that fills the given Job struct with the given frequency

func (*Job) EverySingle

func (j *Job) EverySingle() *Job

EverySingle is deprecated predecessor to Every()

func (*Job) Friday

func (j *Job) Friday() *Job

Friday method fills the given job struct with friday

func (*Job) Hour

func (j *Job) Hour() *Job

Hour method fills the given job struct with hours

func (*Job) Hours

func (j *Job) Hours() *Job

Hours method fills the given job struct with hours

func (*Job) Minute

func (j *Job) Minute() *Job

Minute method fills the given job struct with minutes

func (*Job) Minutes

func (j *Job) Minutes() *Job

Minutes method fills the given job struct with minutes

func (*Job) Monday

func (j *Job) Monday() *Job

Monday method fills the given job struct with monday

func (*Job) Saturday

func (j *Job) Saturday() *Job

Saturday method fills the given job struct with saturday

func (*Job) Second

func (j *Job) Second() *Job

Second method fills the given job struct with seconds

func (*Job) Seconds

func (j *Job) Seconds() *Job

Seconds method fills the given job struct with seconds

func (*Job) Sunday

func (j *Job) Sunday() *Job

Sunday method fills the given job struct with sunday

func (*Job) Thursday

func (j *Job) Thursday() *Job

Thursday method fills the given job struct with thursday

func (*Job) Tuesday

func (j *Job) Tuesday() *Job

Tuesday method fills the given job struct with tuesday

func (*Job) Wednesday

func (j *Job) Wednesday() *Job

Wednesday method fills the given job struct with wednesday

func (*Job) Week

func (j *Job) Week() *Job

Week method fills the given job struct with weeks

func (*Job) Weeks

func (j *Job) Weeks() *Job

Weeks method fills the given job struct with weeks

type Scheduler

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

Scheduler type is used to store a group of jobs (Job structs)

func NewScheduler

func NewScheduler() Scheduler

NewScheduler creates and returns a new Scheduler

func (*Scheduler) Run

func (s *Scheduler) Run()

Run method on the Scheduler type runs the scheduler. This is a blocking method, and should be run as a goroutine.

func (*Scheduler) Schedule

func (s *Scheduler) Schedule() *Job

Schedule method on the Scheduler creates a new Job and prepares is for "filling"

func (*Scheduler) SetPollingInterval

func (s *Scheduler) SetPollingInterval(milliseconds int)

SetPollingInterval sets the time (in milliseconds) which scheduler will spend in sleep during each cycle in the Run method

type TimeUnit

type TimeUnit int

TimeUnit is an numeration used for handling time units internally.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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