近期在学习Golang ,想通过Golang 实现一个Crontab 的管理。虽然github 已经有很多成熟的轮子可以使用。但是还是只有自己的轮子,玩起来才最放心。计划golang 的cron 使用三部分构成,client ,server ,web 端。其中server 端提供定时任务的分发控制,以及监控各个client 的健康状况。Client 端复制执行具体的任务,并且上报日志。web 端根据Server 端提供的RestFul API 来渲染管理后台。

package main

import (
	"fmt"
	"sync"
	"time"
)


/**
创建一个定时器
 */
func main() {
	ticker := time.NewTicker(1*time.Second)
	quit := make(chan int)
	var wg sync.WaitGroup
	wg.Add(1)
	go func(){
		defer wg.Done()
		fmt.Println("child goroutine bootstramp start")
		for {
			select {
				case <-ticker.C:
					fmt.Println("ticker.")
				case <-quit:
					fmt.Println("work well")
					ticker.Stop()
					return
			}
		}
		fmt.Println("child goroutine bootstramp end")
	}()

	time.Sleep(10 * time.Second)
	quit<- 1
	wg.Wait()
}

相关文章:

  • 2021-06-30
  • 2022-12-23
  • 2022-12-23
  • 2019-02-12
  • 2022-12-23
  • 2021-08-01
  • 2021-09-12
  • 2022-12-23
猜你喜欢
  • 2022-02-11
  • 2021-11-28
  • 2021-10-12
  • 2021-08-11
  • 2021-08-03
  • 2022-12-23
相关资源
相似解决方案