schedule

package
v0.156.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 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"
	"database/sql"
	"github.com/adamluzsi/frameless/pkg/logger"
	"github.com/adamluzsi/frameless/pkg/tasker/schedule"
	"log"
	"os"
)

func main() {
	db, err := sql.Open("driverName", os.Getenv("DATABASE_URL"))
	if err != nil {
		logger.Fatal(nil, "error during postgres db opening", logger.ErrField(err))
		os.Exit(1)
	}
	_ = db

	scheduler := schedule.Scheduler{
		LockerFactory: nil, // &postgresql.LockerFactory[string]{DB: db},
		Repository:    nil, // &postgresql.TaskerScheduleStateRepository{DB: db},
	}

	task := scheduler.WithSchedule("db maintenance", schedule.Monthly{Day: 1}, func(ctx context.Context) error {
		return nil
	})

	if err := task(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