Help us shape the future of Go! Take the 2026 Go Developer Survey

graceful

package module
v0.0.0-...-0ec8561 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2019 License: MIT Imports: 6 Imported by: 0

README

gocron-graceful

Graceful shutdown implementation for gocron based worker

Installing

go get github.com/ashulepov/gocron-graceful

Using

package main

import (
	"log"
	"sync"

	"github.com/ashulepov/gocron-graceful"
	"github.com/jasonlvhit/gocron"
)

func main() {
	graceful.Worker("tasks", task)
}

func task(wg *sync.WaitGroup) {
	cron := gocron.NewScheduler()
	cron.Every(1).Seconds().Do(graceful.TaskWrapper, wg, job1)
	cron.Every(2).Seconds().Do(graceful.TaskWrapper, wg, job2)
	go func() {
		<-cron.Start()
	}()
}

func job1() {
	log.Println("job 1")
}

func job2() {
	log.Println("job 2")
}

Testing

Unit-tests:

go test -v

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TaskWrapper

func TaskWrapper(wg *sync.WaitGroup, task func())

TaskWrapper is wrapper for graceful tasks

func Worker

func Worker(name string, task func(wg *sync.WaitGroup))

Worker runs task worker

Types

This section is empty.

Jump to

Keyboard shortcuts

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