gocron icon indicating copy to clipboard operation
gocron copied to clipboard

gocron.Every(5).Minute().Do(func () {}) panics with no clear error

Open marksalpeter opened this issue 10 years ago • 6 comments

gocron.Every(5).Minute().Do(func () {}) panics with no error message, its literally an empty string. this should be equivalent to gocron.Every(5).Minutes().Do(func () {})

marksalpeter avatar Oct 16 '15 22:10 marksalpeter

I ran into the same issue. A little hint would be pretty helpful.

I would fix the messages if we could agree on an useful text like:

"Use Minutes() if you want to schedule intervals > 1min "

The same issue applies to Hour() and Second().

Dennis-Kluge avatar Oct 30 '15 08:10 Dennis-Kluge

:+1: to gocron.Every(5).Minute().Do(func () {}) being an alias of gocron.Every(5).Minutes().Do(func () {}).

Claudiu avatar Nov 03 '15 15:11 Claudiu

If aliasing is an option I would additionally print a message that the function is misused.

Dennis-Kluge avatar Nov 04 '15 09:11 Dennis-Kluge

@HorstMumpitz I don't think it is being misused. If you look at the standard libraries time package every duration is defined in the singular. For example, Its common for example to do something like

fiveMinutes := 5 * time.Minute

It might make sense to remove the plurals. Any thoughts?

marksalpeter avatar Dec 05 '15 21:12 marksalpeter

one thing here is that if you want to pass the number of minutes as an arg of your program you have to do something like :

switch argv[0] {
case 1: gocron.Every(argv[0]).Minute().Do(func () {})
default: gocron.Every(5).Minute*s*().Do(func () {})
}

Which is not very usefull.

as i like to keep my code as readable as possible, i would vote also at least for a clear warning about that missuse or an alias that make it work the nice way :-)

fredleger avatar Aug 12 '17 15:08 fredleger

Why not just deprecate the singular and just use the plural?

gocron.Every(1).Minutes().Do(func(){})

Is still readable.

MovieStoreGuy avatar Sep 04 '17 14:09 MovieStoreGuy