func AddTask(taskname string, t Tasker) {
	AdminTaskList[taskname] = t
	if isstart {
		changed <- true
	}
}
AddTask add task with name
package toolbox
import (
	"log"
	"math"
	"sort"
	"strconv"
	"strings"
	"time"
)
type bounds struct {
	min, max uint
	names    map[string]uint
}
var (
	AdminTaskList map[string]Tasker
	stop          chan bool
	changed       chan bool
	isstart       bool
	seconds       = bounds{0, 59, nil}
	minutes       = bounds{0, 59, nil}
	hours         = bounds{0, 23, nil}
	days          = bounds{1, 31, nil}
	months        = bounds{1, 12, map[string]uint{
		"jan": 1,
		"feb": 2,
		"mar": 3,
		"apr": 4,
		"may": 5,
		"jun": 6,
		"jul": 7,
		"aug": 8,
		"sep": 9,
		"oct": 10,
		"nov": 11,
		"dec": 12,
	}}
	weeks = bounds{0, 6, map[string]uint{
		"sun": 0,
		"mon": 1,
		"tue": 2,
		"wed": 3,
		"thu": 4,
		"fri": 5,
		"sat": 6,
	}}
)
const (
	starBit = 1 << 63
)
type Schedule struct {
	Second uint64
	Minute uint64
	Hour   uint64
	Day    uint64
	Month  uint64
	Week   uint64
}
type TaskFunc func() error
type Tasker interface {
	GetSpec() string
	GetStatus() string
	Run() error
	SetNext(time.Time)
	GetNext() time.Time
	SetPrev(time.Time)
	GetPrev() time.Time
}
type taskerr struct {
	t       time.Time
	errinfo string
}
type Task struct {
	Taskname string
	Spec     *Schedule
	SpecStr  string
	DoFunc   TaskFunc
	Prev     time.Time
	Next     time.Time
	Errlist  []*taskerr  
	ErrLimit int         
}
func NewTask(tname string, spec string, f TaskFunc) *Task {
	task := &Task{
		Taskname: tname,
		DoFunc:   f,
		ErrLimit: 100,
		SpecStr:  spec,
	}
	task.SetCron(spec)
	return task
}
func (t *Task) GetSpec() string {
	return t.SpecStr
}
func (t *Task) GetStatus() string {
	var str string
	for _, v := range t.Errlist {
		str += v.t.String() + ":" + v.errinfo + "<br>"
	}
	return str
}
func (t *Task) Run() error {
	err := t.DoFunc()
	if err != nil {
		if t.ErrLimit > 0 && t.ErrLimit > len(t.Errlist) {
			t.Errlist = append(t.Errlist, &taskerr{t: t.Next, errinfo: err.Error()})
		}
	}
	return err
}
func (t *Task) SetNext(now time.Time) {
	t.Next = t.Spec.Next(now)
}
func (t *Task) GetNext() time.Time {
	return t.Next
}
func (t *Task) SetPrev(now time.Time) {
	t.Prev = now
}
func (t *Task) GetPrev() time.Time {
	return t.Prev
}
func (t *Task) SetCron(spec string) {
	t.Spec = t.parse(spec)
}
func (t *Task) parse(spec string) *Schedule {
	if len(spec) > 0 && spec[0] == '@' {
		return t.parseSpec(spec)
	}
	fields := strings.Fields(spec)
	if len(fields) != 5 && len(fields) != 6 {
		log.Panicf("Expected 5 or 6 fields, found %d: %s", len(fields), spec)
	}
	if len(fields) == 5 {
		fields = append(fields, "*")
	}
	schedule := &Schedule{
		Second: getField(fields[0], seconds),
		Minute: getField(fields[1], minutes),
		Hour:   getField(fields[2], hours),
		Day:    getField(fields[3], days),
		Month:  getField(fields[4], months),
		Week:   getField(fields[5], weeks),
	}
	return schedule
}
func (t *Task) parseSpec(spec string) *Schedule {
	switch spec {
	case "@yearly", "@annually":
		return &Schedule{
			Second: 1 << seconds.min,
			Minute: 1 << minutes.min,
			Hour:   1 << hours.min,
			Day:    1 << days.min,
			Month:  1 << months.min,
			Week:   all(weeks),
		}
	case "@monthly":
		return &Schedule{
			Second: 1 << seconds.min,
			Minute: 1 << minutes.min,
			Hour:   1 << hours.min,
			Day:    1 << days.min,
			Month:  all(months),
			Week:   all(weeks),
		}
	case "@weekly":
		return &Schedule{
			Second: 1 << seconds.min,
			Minute: 1 << minutes.min,
			Hour:   1 << hours.min,
			Day:    all(days),
			Month:  all(months),
			Week:   1 << weeks.min,
		}
	case "@daily", "@midnight":
		return &Schedule{
			Second: 1 << seconds.min,
			Minute: 1 << minutes.min,
			Hour:   1 << hours.min,
			Day:    all(days),
			Month:  all(months),
			Week:   all(weeks),
		}
	case "@hourly":
		return &Schedule{
			Second: 1 << seconds.min,
			Minute: 1 << minutes.min,
			Hour:   all(hours),
			Day:    all(days),
			Month:  all(months),
			Week:   all(weeks),
		}
	}
	log.Panicf("Unrecognized descriptor: %s", spec)
	return nil
}
func (s *Schedule) Next(t time.Time) time.Time {
	t = t.Add(1*time.Second - time.Duration(t.Nanosecond())*time.Nanosecond)
	added := false
	yearLimit := t.Year() + 5
WRAP:
	if t.Year() > yearLimit {
		return time.Time{}
	}
	for 1<<uint(t.Month())&s.Month == 0 {
		if !added {
			added = true
			t = time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, t.Location())
		}
		t = t.AddDate(0, 1, 0)
		if t.Month() == time.January {
			goto WRAP
		}
	}
	for !dayMatches(s, t) {
		if !added {
			added = true
			t = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
		}
		t = t.AddDate(0, 0, 1)
		if t.Day() == 1 {
			goto WRAP
		}
	}
	for 1<<uint(t.Hour())&s.Hour == 0 {
		if !added {
			added = true
			t = time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), 0, 0, 0, t.Location())
		}
		t = t.Add(1 * time.Hour)
		if t.Hour() == 0 {
			goto WRAP
		}
	}
	for 1<<uint(t.Minute())&s.Minute == 0 {
		if !added {
			added = true
			t = time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), 0, 0, t.Location())
		}
		t = t.Add(1 * time.Minute)
		if t.Minute() == 0 {
			goto WRAP
		}
	}
	for 1<<uint(t.Second())&s.Second == 0 {
		if !added {
			added = true
			t = time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), 0, t.Location())
		}
		t = t.Add(1 * time.Second)
		if t.Second() == 0 {
			goto WRAP
		}
	}
	return t
}
func dayMatches(s *Schedule, t time.Time) bool {
	var (
		domMatch = 1<<uint(t.Day())&s.Day > 0
		dowMatch = 1<<uint(t.Weekday())&s.Week > 0
	)
	if s.Day&starBit > 0 || s.Week&starBit > 0 {
		return domMatch && dowMatch
	}
	return domMatch || dowMatch
}
func StartTask() {
	if isstart {
		return
	}
	isstart = true
	go run()
}
func run() {
	now := time.Now().Local()
	for _, t := range AdminTaskList {
		t.SetNext(now)
	}
	for {
		sortList := NewMapSorter(AdminTaskList)
		sortList.Sort()
		var effective time.Time
		if len(AdminTaskList) == 0 || sortList.Vals[0].GetNext().IsZero() {
			effective = now.AddDate(10, 0, 0)
		} else {
			effective = sortList.Vals[0].GetNext()
		}
		select {
		case now = <-time.After(effective.Sub(now)):
			for _, e := range sortList.Vals {
				if e.GetNext() != effective {
					break
				}
				go e.Run()
				e.SetPrev(e.GetNext())
				e.SetNext(effective)
			}
			continue
		case <-changed:
			continue
		case <-stop:
			return
		}
	}
}
func StopTask() {
	if isstart {
		isstart = false
		stop <- true
	}
}