Failed to schedule cron job at night

278 views
Skip to first unread message

Vikram Ingawale

unread,
May 8, 2020, 6:16:31 AM5/8/20
to golang-nuts
Hello Gophers ,

I am using the standard cron package to schedule cron job at midnight. but my cron job is not started at night time. 

for day time it works properly .

my cron expression is 0 15 3 * * * means at midnight 03:15 AM daily


Kurtis Rader

unread,
May 8, 2020, 1:49:44 PM5/8/20
to Vikram Ingawale, golang-nuts
I don't see what this has to do with Go but the problem is your crontab spec says to run the job at 15:00 hours on the third day of each month. Remove the leading "0".

--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

Brian Candler

unread,
May 8, 2020, 2:27:41 PM5/8/20
to golang-nuts
The go cron package (that the OP linked to) allows an optional seconds field to be included.

Vikram Ingawale

unread,
May 8, 2020, 2:40:51 PM5/8/20
to Brian Candler, golang-nuts
just i was scheduled below job but not logged given msg

c.AddFunc("0 0 * * *"func() {
    log.Println("Job started at 12:00AM")
  })

above exp means 0 hr 0min means 12AM right .. 


On Sat, May 9, 2020 at 12:08 AM Brian Candler <b.ca...@pobox.com> wrote:
On 08/05/2020 19:35, Vikram Ingawale wrote:
just i was scheduled below job but not logged given msg

c.AddFunc("0 0 * * *"func() {
    log.Println("Job started at 12:00AM")
  })

above exp means 0 hr 0min means 12AM right .. 

Reply to the list please.

Brian Candler

unread,
May 8, 2020, 2:50:35 PM5/8/20
to golang-nuts
It looks like there are two different things here.

Originally you said: "my cron expression is 0 15 3 * * * means at midnight 03:15 AM daily"

Midnight has a specific meaning in English (00:00), so I interpreted that as intending to say "overnight at 03:15AM".  The second question was about midnight, and "0 0 * * *" is correct for that.

However, I cannot give any concrete reason why the go cron package that you linked to would not run a job at either of those times.  Perhaps you're not using the package correctly?  Perhaps there is a bug in the cron package?  (Seems unlikely, given that 73 other packages import it)

It would be good if you could provide a full program which reproduces the issue, and also state what versions of go and the cron package you are using, and on what platform (Linux, Windows etc).

Vikram Ingawale

unread,
May 8, 2020, 2:56:47 PM5/8/20
to Brian Candler, golang-nuts
Go version : go version go1.14 windows/amd64
platform   :  Windows  
Code : 
package main

import (
  "log"


)

func main() {
  g := gin.Default()

  c := cron.New()
  c.AddFunc("0 0 * * *"func() {
    log.Println("Job started at 12:00AM")
  })
  c.AddFunc("0 1 * * *"func() {
    log.Println("Job started at 01:00AM")
  })
  c.AddFunc("15 2 * * *"func() {
    log.Println("Job started at 02:15AM")
  })
  c.AddFunc("5 3 * * *"func() {
    log.Println("Job started at 03:05AM")
  })
  c.AddFunc("35 4 * * *"func() {
    log.Println("Job started at 04:35AM")
  })
  c.AddFunc("50 5 * * *"func() {
    log.Println("Job started at 05:50AM")
  })
  c.Start()

  g.Run(":8085")
}

 

Brian Candler

unread,
May 9, 2020, 3:30:54 AM5/9/20
to golang-nuts
I left that program running overnight.  This morning I found:

root@builder:~# go get github.com/gin-gonic/gin
root@builder:~# go get gopkg.in/robfig/cron.v2
root@builder:~# go run x.go
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

[GIN-debug] Listening and serving HTTP on :8085
2020/05/09 00:00:00 Job started at 12:00AM
2020/05/09 01:00:00 Job started at 01:00AM
2020/05/09 02:15:00 Job started at 02:15AM
2020/05/09 03:05:00 Job started at 03:05AM
2020/05/09 04:35:00 Job started at 04:35AM
2020/05/09 05:50:00 Job started at 05:50AM

This is under Linux (Ubuntu 16.04) with go 1.13.4

It's possible that the cron library doesn't work properly under Windows, and/or it doesn't work properly under go 1.14.

What exact version of go did you use - when you say 1.14 do you mean 1.14.0 ?  There were some major changes (in particular preemptive scheduling), and subsequent patch releases have fixed some bugs.  If you didn't use 1.14.2, then retest with that.

If it still fails with 1.14.2, then I suggest you either take this to the github tracker for the cron package, or look at what cron is doing under the hood and see if you can reproduce the problem under Windows in a few lines of code that *doesn't* use the cron library.

Vikram Ingawale

unread,
May 9, 2020, 4:13:00 AM5/9/20
to Brian Candler, golang-nuts

Thanks for your help.

I am using go 1.14.0 

Ok I’m updates it to 1.14.2 and then checking Tonight 

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/cfda6002-8d49-4b50-83a2-a9d191f01031%40googlegroups.com.
--
Thanks,
Vikram Ingawale
ph : +91 9766984458

Vikram Ingawale

unread,
May 11, 2020, 2:33:49 AM5/11/20
to Brian Candler, golang-nuts
Using   ("15 2 * * ?")  this exp it works properly for me.
Thanks

Reply all
Reply to author
Forward
0 new messages