duty

module
v0.0.0-...-eef338d Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2019 License: MIT

README

Duty

Go Library for managing long running persistent tasks

Build Status Go Report Card license

Task definition


type PrintTask struct {
	Output string
}


func (t PrintTask) Run() error {
	fmt.Println(t.Output)
	return nil
}

func (PrintTask) Type() string {
	return "print"
}

Task scheduling

d := duty.New(storage.NewMemoryStorage(), duty.Default)
d.Enqueue(PrintTask{Output: "Hello World!"})

Task monitoring (sync)

d := duty.New(storage.NewMemoryStorage(), duty.Default)

task, _ := d.Enqueue(PrintTask{Output: "Hello World!"})

task, _ = d.Get(task.ID)

fmt.Println(task.Status.State)

Task monitoring (async)

	
wg := sync.WaitGroup{}
wg.Add(1)

d := duty.New(storage.NewMemoryStorage(), duty.Options{
	ResultCallback: func(result pool.ScheduledTaskResult) {
		fmt.Println("Got task status " + result.ScheduledTask.ID + ": " + result.Status.State)
		if result.Status.Completed {
			wg.Done()
		}
	},
})

d.Init()

d.Enqueue(PrintTask{
	Output: "test",
})

wg.Wait()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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