gronx icon indicating copy to clipboard operation
gronx copied to clipboard

tried so hard

Open joe-at-startupmedia opened this issue 1 year ago • 5 comments

I started getting this error last night. My suspicion is that it may be related to standard time switchover? Nothing has been changed with the code nor the configuration for months.

Code:

func (j *JobSpec) setNextTick(refTime time.Time, includeRefTime bool) error {
  if j.Cron != "" {
    t, err := gronx.NextTickAfter(j.Cron, refTime, includeRefTime)
    j.nextTick = t
    fmt.Printf("\njCron: %s, refTime: %v, includeRefTime: %v, %-v\n", j.Cron, refTime, includeRefTime, err)
    return err
  }
  return nil
}

Couple instance of failures:

jCron: 10 12 * * *, refTime: 2024-11-02 19:39:33.031482225 -0400 EDT, includeRefTime: true, tried so hard
jCron: 15 05 * * *, refTime: 2024-11-02 19:40:14.304755524 -0400 EDT, includeRefTime: true, tried so hard
jCron: 20 05 * * *, refTime: 2024-11-02 19:40:36.725177004 -0400 EDT, includeRefTime: true, tried so hard

The same code works for other instances:

jCron: 15 00  * * *, refTime: 2024-11-02 19:40:36.723989643 -0400 EDT, includeRefTime: true, <nil>

jCron: 25 00 * * *, refTime: 2024-11-02 19:40:36.724409077 -0400 EDT, includeRefTime: true, <nil>

jCron: 35 00 * * *, refTime: 2024-11-02 19:40:36.724593286 -0400 EDT, includeRefTime: true, <nil>

jCron: 0 0 1 * *, refTime: 2024-11-02 19:40:36.724980983 -0400 EDT, includeRefTime: true, <nil>

joe-at-startupmedia avatar Nov 02 '24 23:11 joe-at-startupmedia

version is: github.com/adhocore/gronx v1.8.1

joe-at-startupmedia avatar Nov 02 '24 23:11 joe-at-startupmedia

Update:

The following modification fixes the issue:

func (j *JobSpec) setNextTick(refTime time.Time, includeRefTime bool) error {
  if j.Cron != "" {
    refTime, _ = time.Parse(time.RFC3339, refTime.Format(time.RFC3339))
    t, err := gronx.NextTickAfter(j.Cron, refTime, includeRefTime)
    j.nextTick = t
    return err
  }
  return nil
}

2024-11-02 19:40:36.723989643 -0400 EDT, I'm not sure where this time format is coming from but it seems to be the source of the issue. The code replicating this issue is coming from cheek where s.loc is declared from America/New_York

joe-at-startupmedia avatar Nov 03 '24 00:11 joe-at-startupmedia

hello Joe, thanks for reporting issue. first, could you check if latest version is working?

adhocore avatar Nov 07 '24 06:11 adhocore

At the time of the issue, I had cecked if upgrading to the latest verion of gronx fixed the issue: it did not. In my ability to replicate on an isolated environment, I could not replicate because the now function was not producing the following format:

2024-11-02 19:40:36.725177004 -0400 EDT

While checking the docs for the std time package, I could not find a name for that format, nor was I able to successfully parse a string from that format into a new time instance without errors. At this point, the issue may not be replicable on a revert from my fix above due to the rollover to standard time, but I will try it later and provide an update.

joe-at-startupmedia avatar Nov 07 '24 10:11 joe-at-startupmedia

checking out the commit before my fix above, no longer produces the error as I had suspected. And the code is still producing the following format:

2024-11-10 15:54:42.130695329 -0500 EST

Commit: https://github.com/joe-at-startupmedia/cheek-turner/commit/216a4becdeedca7fe467abf754512e4cc171fea2

I'd be of more service if I knew how to parse this format without errors.

go playground

In order to replicate the issue, the time has to go back to the following:

2024-11-02 19:40:36.725177004 -0400 EDT

joe-at-startupmedia avatar Nov 10 '24 21:11 joe-at-startupmedia