Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I have two tasks but only execute one #351

Open
cy0405 opened this issue Nov 17, 2020 · 0 comments
Open

I have two tasks but only execute one #351

cy0405 opened this issue Nov 17, 2020 · 0 comments

Comments

@cy0405
Copy link

cy0405 commented Nov 17, 2020

package main

import (
"fmt"
"github.com/robfig/cron"
"net/http"
"strings"
"time"
)

//周一至周五每天早上10点至下午6点提醒喝水
func main() {
fmt.Println("程序开始时间======",time.Now())
c := cron.New()

//spec := "0 0 9,10,11,12,14,15,16,17,18 * * ? "
spec := "0 0 9,10,11,12,14,15,16,17,18 * * ?"

err:=c.AddFunc(spec, func() {
	fmt.Println("time=====",time.Now())
	fmt.Println("=======================开始执行喝水任务=======================")

	url := "http://ep.yoozoo.com/api/feishu/msg"
	payload := strings.NewReader("{\n\t\"msg_type\": \"text\",\n    \"account\": \"oc_f1d263808c91f074b0eef45a782c92fd\",\n    \"send_obj\": \"chat\",\n    \"text\": \"记得喝水哦\"\n}")
	req, _ := http.NewRequest("POST", url, payload)


	req.Header.Add("content-type", "application/json")
	req.Header.Add("cache-control", "no-cache")

	_,e:=http.DefaultClient.Do(req)
	if e!=nil {
		fmt.Println("http do err:======",e)
		return
	}


})
err=c.AddFunc(spec, func() {
	fmt.Println("=======================开始执行吃饭任务=======================")
	fmt.Println("time=====",time.Now())

})
if err!=nil{
	fmt.Println(" AddFunc err=====",err)
}
c.Start()
select {}

}

GOROOT=/usr/local/Cellar/go/1.15.2/libexec #gosetup
GOPATH=/Users/chenbo/go #gosetup
/usr/local/Cellar/go/1.15.2/libexec/bin/go build -o /private/var/folders/mb/xf7blvj94tb09rqxmqlhsj8c0000gn/T/___go_build_drink_water drink-water #gosetup
/private/var/folders/mb/xf7blvj94tb09rqxmqlhsj8c0000gn/T/___go_build_drink_water
程序开始时间====== 2020-11-17 09:50:03.728168 +0800 CST m=+0.000518304
=======================开始执行吃饭任务=======================
time===== 2020-11-17 10:00:00.000498 +0800 CST m=+596.277799346
time===== 2020-11-17 10:00:00.000329 +0800 CST m=+596.277630310
=======================开始执行喝水任务=======================
=======================开始执行吃饭任务=======================
time===== 2020-11-17 11:00:00.00356 +0800 CST m=+4196.345111085
time===== 2020-11-17 11:00:00.003544 +0800 CST m=+4196.345095894
=======================开始执行喝水任务=======================

version require github.com/robfig/cron v1.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant