Giter VIP home page Giter VIP logo

Comments (7)

brianberzins avatar brianberzins commented on August 17, 2024 2

Well... my mind is kinda blown right now... Apparently the cron library is using the first value as seconds instead of minutes...

package main

import (
	"fmt"

	"github.com/robfig/cron"
)

func printNext(s string) {
	schedule := cron.New()
	schedule.AddFunc(s, func() {})
	schedule.Start()
	entry := schedule.Entries()[0]
	fmt.Println(entry.Next.String())
}

func main() {
	printNext("1 2 3 4 5")
}

Results in:

2020-05-04 03:02:01 -0500 CDT

And given that the (documentation)[https://godoc.org/github.com/robfig/cron#hdr-Alternative_Formats] says...

Alternative Cron expression formats support other fields like seconds. You can implement that by creating a custom Parser as follows.

And given that I definitely didn't do that (here)[https://github.com/target/pod-reaper/blob/master/reaper/reaper.go#L98] I'm going to have to dig deeper on this one.

For an ultra quick fix, based on what's currently out there, adding a zero to this perplexing "seconds" value should get you going 0 0 20 * * *

func main() {
	printNext("0 20 * * *")
	printNext("0 0 20 * * *")
}

Results in:

2020-03-27 07:20:00 -0500 CDT
2020-03-27 20:00:00 -0500 CDT

More to come on this...

from pod-reaper.

brianberzins avatar brianberzins commented on August 17, 2024

Well... turns out the version of the library that I've been using has a surprise (to me anyway)

var defaultParser = NewParser(
	Second | Minute | Hour | Dom | Month | DowOptional | Descriptor,
)

Also, the defaultParser was removed entirely in (this commit)[https://github.com/robfig/cron/commit/1f8ec97c87338ef2c06af340dcf4289c691c6f95#diff-f615844d3497ff38db57e459d6ef657b]

So now that I know what's going on, it seems like it's just a matter of updating the dependency... just with one small note: I'd like to make sure I don't break anyone currently using that seconds field.

I think that means my best bet forward would be to actually use a customer parser using the optionalSeconds flag provided in the library. My hope is that it will function like this:

  • got 6 fields? great, we'll assume you're starting with seconds
  • got 5 fields? great, we'll assume you're starting with minutes

from pod-reaper.

jnavarro86 avatar jnavarro86 commented on August 17, 2024

Sounds like a plan.

I don't know much about go, but I guess you could pin the version of the cron library to avoid future breaking changes.

Thank you very much for your quick response!

from pod-reaper.

brianberzins avatar brianberzins commented on August 17, 2024

The newest version of that cron dependency has this.

var standardParser = NewParser(
	Minute | Hour | Dom | Month | Dow | Descriptor,
)

I don't really see a way to NOT break this without leaving the seconds value... because (of all things) that previous version had an optional Day of Week value. That's extremely ugly...

Honestly, I think that means that I need need to bite this and get it to where I want it.
PR incoming in not too long.

from pod-reaper.

brianberzins avatar brianberzins commented on August 17, 2024

Guess this helps explain #39 huh? 😄
edit: formatting

from pod-reaper.

jnavarro86 avatar jnavarro86 commented on August 17, 2024

Guess I does!
oops

from pod-reaper.

brianberzins avatar brianberzins commented on August 17, 2024

docker images with this:

  • target/pod-reaper:latest
  • target/pod-reaper:2.6.0

from pod-reaper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.