jasonlvhit / gocron

A Golang Job Scheduling Package.
BSD 2-Clause "Simplified" License
3.47k stars 345 forks source link

possibility to perform a schedule from HH:MM till HH:MM ? #68

Open vi7Ch opened 5 years ago

vi7Ch commented 5 years ago

Hi,

Do you know whether it would be possible to include a from HH:MM till HH:MM feature ? Let's say I want to schedule a task every 5MIN from Monday to Friday, from 8:00 till 18:30.

maybe with a
gocron.Clear()

<- gocron.Start()

That would be a good feature if it is currently not possible.

Any idea ?

Thanks,

ngethe commented 5 years ago

I think you can do gocron.Every(1).Day().At("8:00").Do(task_start) to start the task

gocron.Every(1).Day().At("18:30").Do(task_stop) to stop the task

neuyilan commented 5 years ago

I think you can do gocron.Every(1).Day().At("8:00").Do(task_start) to start the task

gocron.Every(1).Day().At("18:30").Do(task_stop) to stop the task

LGTM, prefect!

iambudi commented 4 years ago

I think you can do gocron.Every(1).Day().At("8:00").Do(task_start) to start the task

gocron.Every(1).Day().At("18:30").Do(task_stop) to stop the task

How to run it Every 5 Minutes? It only run once at 8:00?

JohnRoesler commented 4 years ago

Expanding on the example - this works:

package main

import (
    "log"

    "github.com/jasonlvhit/gocron"
)

func task() {
    log.Println("I am runnning task.")
}

func task_start() {
    log.Println("Starting the task.")
    gocron.Every(5).Minutes().From(gocron.NextTick()).Do(task)
}

func task_stop() {
    log.Println("Stopping the task.")
    gocron.Remove(task)
}

func main() {
    gocron.Every(1).Day().At("08:00").Do(task_start)
    gocron.Every(1).Day().At("18:30").Do(task_stop)
    <-gocron.Start()
}
iambudi commented 4 years ago

@JohnRoesler Perfect! thanks.