schedule

package
v0.131.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Daily

type Daily struct {
	Hour, Minute int
	Location     *time.Location
}

func (Daily) UntilNext

func (i Daily) UntilNext(lastRanAt time.Time) time.Duration

type Interval

type Interval time.Duration

func (Interval) UntilNext

func (i Interval) UntilNext(lastRanAt time.Time) time.Duration

type Monthly

type Monthly struct {
	Day, Hour, Minute int
	Location          *time.Location
}

func (Monthly) UntilNext

func (i Monthly) UntilNext(lastRanAt time.Time) time.Duration

type Scheduler

type Scheduler struct {
	LockerFactory locks.Factory[string]
	Repository    StateRepository
}

func (Scheduler) WithSchedule

func (s Scheduler) WithSchedule(jobid string, interval tasker.Interval, job tasker.Task) tasker.Task
Example
package main

import (
	"context"
	"github.com/adamluzsi/frameless/adapters/memory"
	"github.com/adamluzsi/frameless/pkg/tasker/schedule"
	"log"
	"time"
)

func main() {
	m := schedule.Scheduler{
		LockerFactory: memory.NewLockerFactory[string](),
		Repository:    memory.NewRepository[schedule.State, string](memory.NewMemory()),
	}

	job := m.WithSchedule("db maintenance", schedule.Interval(time.Hour*24*7), func(ctx context.Context) error {
		// this job is scheduled at every seven days
		return nil
	})

	if err := job(context.Background()); err != nil {
		log.Println("ERROR", err.Error())
	}
}
Output:

type State

type State struct {
	ID        string `ext:"id"`
	Timestamp time.Time
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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