bamzi / jobrunner

Framework for performing work asynchronously, outside of the request flow
MIT License
1.04k stars 99 forks source link

Jobs Only Run Once #19

Closed favians closed 4 years ago

favians commented 4 years ago

Why my jobrunner only run once after the program starting? Im currently set my jobrunner "@midnight" / "0 0 * * *" , this jobrunner only run once after program started (or even not running at all), and the next day nothing happend. Any wrong / missing with my code?

Here my code:

Expired.go

package expired

type Expired struct {
}

func (Expired) Run() {
    log.Println("Expired")
}

Main.go

package main

import (
    "project/expired"
    "project/router"
    "github.com/bamzi/jobrunner"
)

func main() {
        e := router.New()
        jobrunner.Start()

        jobrunner.Schedule("0 0 * * *", expired.Expired{})

        e.Start(":9000")
        os.Exit(0)
}

thank you. . .

bamzi commented 4 years ago

First, typically these questions are for Stackoverflow. Second the role of JobRunner is a JIT (just-in-time) cron scheduler. For example, when a request comes to POST /users you schedule jobs to send emails, to checks or validations etc...

I think what you're looking for is a cron job orchestration something along the lines of crontab or chronos or even using the github.com/robfig/cron/v3@v3.0.0 directly without the JobRunner interface in a long polling service.

re:your code > the parts involving JobRunner are ok, however the cron specification for @everyday midnight would be 0 0 0 ? * * *