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

runtime error: invalid memory #31

Open
RealLau opened this issue Sep 7, 2020 · 1 comment
Open

runtime error: invalid memory #31

RealLau opened this issue Sep 7, 2020 · 1 comment

Comments

@RealLau
Copy link

RealLau commented Sep 7, 2020

I just encountered a runtime error, the logs is as below:

goroutine 1526 [running]:
log.(*Logger).Panic(0xc0005440f0, 0xc000467c00, 0x3, 0x3)
        /Users/smy/sdk/go1.13.8/src/log/log.go:212 +0xaa
github.com/bamzi/jobrunner.(*Job).Run.func1()
        /Users/smy/go/pkg/mod/github.com/bamzi/[email protected]/jobrunner.go:55 +0x1a5
panic(0xe86880, 0x1804d70)
        /Users/smy/sdk/go1.13.8/src/runtime/panic.go:679 +0x1b2
main.UpdateNews.Run()
        /Users/smy/go/src/GBlog/main.go:29 +0x89
github.com/bamzi/jobrunner.(*Job).Run(0xc0000a7090)
        /Users/smy/go/pkg/mod/github.com/bamzi/[email protected]/jobrunner.go:75 +0x188
github.com/robfig/cron/v3.(*Cron).startJob.func1(0xc000248b40, 0x10f8a80, 0xc0000a7090)
        /Users/smy/go/pkg/mod/github.com/robfig/cron/[email protected]/cron.go:307 +0x69
created by github.com/robfig/cron/v3.(*Cron).startJob
        /Users/smy/go/pkg/mod/github.com/robfig/cron/[email protected]/cron.go:305 +0x73
^[[97;45m[JobRunner] 2020/09/07 - 09:14:54 Started... ^[[0m

my code is simple as send a http get request in a every 5min job:

func (e UpdateNews) Run() {
	resp, err := http.Get("https://sample_site.com/common/update_news/")
	if err != nil {
		fmt.Println("Call update news failed")
	}
	var res map[string]interface{}
	json.NewDecoder(resp.Body).Decode(&res)
	resCode := fmt.Sprintf("%v", res["code"])
	if resCode == "0" {
		fmt.Printf("Every 5 mins update news success.")
	}
}
func main(){
jobrunner.Start() // optional: jobrunner.Start(pool int, concurrent int) (10, 1)
	err := jobrunner.Schedule("@every 300s", UpdateNews{})
	if err != nil {
		panic(err)
	}
}
@bamzi
Copy link
Owner

bamzi commented Sep 7, 2020

You need to declare UpdateNews{}

type UpdateNews struct {}

Also the error response from jobrunner.Schedule... is related to parsing of cron. Maybe 300s should 5m

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

2 participants