sterling

package module
v0.0.0-...-41e3741 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: BSD-3-Clause Imports: 6 Imported by: 0

README

Sterling

PkgGoDev Go Report Card

A simple event scheduler built on top of tailetc.

// Create a scheduler
s, _ := sterling.NewScheduler("memory://", log.Printf)
done := make(chan struct{})
// Listen for events of type "send email" and process them with a callback
go s.Listen("send email", func(payload string) {
    fmt.Println(payload)
    close(done)
})
// Schedule events with a payload at specific times
_ = s.Schedule(time.Now(), "send email", "hello world")
<-done
// Output: hello world

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Scheduler

type Scheduler interface {
	Schedule(t time.Time, event, payload string) error
	Listen(event string, f func(payload string))
}

Scheduler defines a simple interface to schedule and listen for time-based events.

Example
package main

import (
	"fmt"
	"github.com/mewil/sterling"
	"log"
	"time"
)

func main() {
	// Create a scheduler
	s, _ := sterling.NewScheduler("memory://", log.Printf)
	done := make(chan struct{})
	// Listen for events of type "send email" and process them with a callback
	go s.Listen("send email", func(payload string) {
		fmt.Println(payload)
		close(done)
	})
	// Schedule events with a payload at specific times
	_ = s.Schedule(time.Now(), "send email", "hello world")
	<-done
}
Output:

hello world

func NewScheduler

func NewScheduler(urls string, logf func(format string, args ...interface{})) (Scheduler, error)

NewScheduler creates a new scheduler that users tailetc. The first argument is the same as the second argument of tailetc.New and specifies whether the data is stored in memory, on disk, or in an etcd cluster. The scheduler will log information using the function passed to logf.

Jump to

Keyboard shortcuts

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