Cron job (2nd monday of every month/ 3rd tuesday of every month)

151 views
Skip to first unread message

kumargv

unread,
Aug 11, 2016, 8:11:36 AM8/11/16
to golang-nuts
Hello  guys,

i am using this cron pkg 


what i am trying to achieve here is 
1) run a job on  2nd friday of every month
 2)run a job on  4nd sunday of every month
3)run a job on 1 monday of every month 
etc 



Please suggest 

thanks 

Tamás Gulácsi

unread,
Aug 11, 2016, 10:02:12 AM8/11/16
to golang-nuts
// The first monday can be 1-7th, the second 8-14th day of the month.
c.AddFunc("0 30 * 8-14 * 1", func() { fmt.Println("second monday of every month") })

// The first tuesday can be 1-7th, the second 8-14th, the third 15-22th.
c.AddFunc("0 30 * 15-22 * 2", func() { fmt.Println("3rd tuesday of every month") })

vijay giri

unread,
Aug 16, 2016, 3:58:56 AM8/16/16
to Tamás Gulácsi, golang-nuts
I tested but it is not working .


OUTPUT

C:\Users\vijay\Desktop>go run cron.go
EVERY ONE MINUTE
second monday of every month
3rd tuesday of every month
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
EVERY ONE MINUTE


--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/XT0QD4hwkVM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tamás Gulácsi

unread,
Aug 16, 2016, 8:39:22 AM8/16/16
to golang-nuts, tgula...@gmail.com
TL;DR cron works like this (see the man page): https://github.com/robfig/cron/blob/v2/spec.go#L164
It means that the dow and dom restrictions are ORed, not ANDed together.

I'd say to your original problem, that choose one restriction (say, dow), and restrict in the called function: https://play.golang.org/p/aVWj_HAPX9
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages