Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add another out channel so we can properly report lastRun #700

Merged
merged 4 commits into from
Mar 26, 2024

Conversation

JohnRoesler
Copy link
Contributor

@JohnRoesler JohnRoesler commented Mar 23, 2024

What does this do?

With a change in how the lastrun was being reporting to handle rescheduling, we needed to also update how lastRun is being recorded to actually track when the job was run vs. when it was sent back for rescheduling.

Which issue(s) does this PR fix/relate to?

resolves #694
resolves #685

List any changes that modify/break current functionality

Have you included tests for your changes?

DONE Need to update with a test: manual testing confirms:

singleton mode issue

package main

import (
	"fmt"
	"log"
	"time"

	"github.com/go-co-op/gocron/v2"
)

func main() {
	s, _ := gocron.NewScheduler()
	s.Start()

	j, _ := s.NewJob(
		gocron.DurationJob(2*time.Second),
		gocron.NewTask(func() {
			log.Println("job running")
			time.Sleep(3 * time.Second)
			log.Println("job done")
		}),
		gocron.WithSingletonMode(gocron.LimitModeWait),
	)

	for {
		time.Sleep(1 * time.Second)
		lastRun, err := j.LastRun()
		if err != nil {
			fmt.Printf("job lastRun error: %s\n", err)
			continue
		}
		fmt.Printf("job lastRun: %s\n", lastRun)
	}

}

RunNow issue

package main

import (
	"fmt"
	"log"
	"time"

	"github.com/go-co-op/gocron/v2"
)

func main() {
	s, _ := gocron.NewScheduler()
	s.Start()

	j, _ := s.NewJob(
		gocron.DurationJob(10*time.Second),
		gocron.NewTask(func() {
			log.Println("job running")
			time.Sleep(3 * time.Second)
			log.Println("job done")
		}),
		gocron.WithSingletonMode(gocron.LimitModeWait),
	)

	for {
		time.Sleep(1 * time.Second)
		lastRun, err := j.LastRun()
		if err != nil {
			fmt.Printf("job lastRun error: %s\n", err)
			continue
		}
		fmt.Printf("job lastRun: %s\n", lastRun)

		log.Println("running job now")
		j.RunNow()
	}

}

Did you document any new/modified functionality?

  • Updated example_test.go
  • Updated README.md

Notes

@JohnRoesler JohnRoesler merged commit 9ae7545 into v2 Mar 26, 2024
3 checks passed
@JohnRoesler JohnRoesler deleted the calculate-lastrun branch March 26, 2024 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant