Go-实现程序零点定时启动
2017-12-03 16:33
375 查看
需要实现定时启动,这里采用的是定时器的方式进行,当然可以使用ticket,代码如下:
package main
import(
"time"
)
func WriteWork(writereload func()) {
go func() {
writereload()
for {
now := time.Now()
// 下一个零点
next := now.Add(time.Hour * 24)
next = time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, next.Location())
t := time.NewTimer(next.Sub(now))
defer LogFile.Close()
writereload()
<-t.C
}
}()
}
func WriteReload(){
//init work
fmt.Println("start...")
}
func main(){
WriteWork(WriteReload)
}
package main
import(
"time"
)
func WriteWork(writereload func()) {
go func() {
writereload()
for {
now := time.Now()
// 下一个零点
next := now.Add(time.Hour * 24)
next = time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, next.Location())
t := time.NewTimer(next.Sub(now))
defer LogFile.Close()
writereload()
<-t.C
}
}()
}
func WriteReload(){
//init work
fmt.Println("start...")
}
func main(){
WriteWork(WriteReload)
}
相关文章推荐
- 利用liunx的 crontab 和 php 的 pcntl_fork() 实现定时启动的多线程php程序
- Go1.8实现watchdog功能,实现依赖启动服务程序
- c# 利用Time实现定时启动程序
- C#程序启动欢迎窗体实现(转)
- Linux如何实现开机启动程序详解
- 在WINDOWS任务计划程序下执行PHP文件 PHP定时功能的实现
- Linux CPP程序的三种实现定时任务的方法
- 在VC中实现程序在启动时隐藏
- 通过异步程序调用(APC)实现的定时功能 CreateWaitableTimer和SetWaitableTimer函数
- 使用System.Timers.Timer类实现程序定时执行
- VC++ 实现VC程序启动时最小化到任务栏(完美解决闪烁问题)
- c#实现程序启动唯一实例的方法
- Linux如何实现开机启动程序详解
- 如何实现定时执行php的程序
- 把Node.js程序加入服务实现随机启动
- Go:去除程序启动时的控制台窗口
- C#实现一个用于开机启动其他程序的Windows服务
- SetWaitableTimer 通过异步程序调用(APC)实现的定时功能
- 通过启动组实现程序随系统启动
- 在C#中启动另一个程序的实现方法