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

feat: add dynamic limit mode update functionality, closes #768 #788

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from

Conversation

pcfreak30
Copy link
Contributor

  • Add GetLimitMode method to retrieve current limit mode configuration
  • Implement UpdateScheduler method to modify scheduler settings at runtime
  • Create WithUpdateLimitMode option for updating limit mode and concurrency limit
  • Add corresponding unit tests for new functionality

- Add GetLimitMode method to retrieve current limit mode configuration
- Implement UpdateScheduler method to modify scheduler settings at runtime
- Create WithUpdateLimitMode option for updating limit mode and concurrency limit
- Add corresponding unit tests for new functionality
@pcfreak30
Copy link
Contributor Author

pcfreak30 commented Jan 2, 2025

@JohnRoesler could you please let me know what you need from me to get my PR's merged?

Really need to get off maintaining a fork of the repo.

Kudos.

@JohnRoesler
Copy link
Contributor

JohnRoesler commented Jan 3, 2025

This PR introduces race conditions as seen in the test output

Click to expand log output
=== RUN   TestScheduler_UpdateScheduler
=== RUN   TestScheduler_UpdateScheduler/Update_from_no_limit_to_wait_mode
2025/01/02 16:59:07 INFO: gocron: new scheduler created
2025/01/02 16:59:07 DEBUG: gocron: scheduler starting
2025/01/02 16:59:07 INFO: gocron: scheduler started
2025/01/02 16:59:07 DEBUG: gocron: stopping scheduler
2025/01/02 16:59:07 DEBUG: gocron: executor started
2025/01/02 16:59:07 DEBUG: gocron: stopping executor
2025/01/02 16:59:07 DEBUG: gocron: waiting for standard jobs to complete
2025/01/02 16:59:07 DEBUG: gocron: standard jobs completed
2025/01/02 16:59:07 DEBUG: gocron: waiting for singleton jobs to complete
2025/01/02 16:59:07 DEBUG: gocron: singleton jobs completed
2025/01/02 16:59:07 DEBUG: gocron: waiting for limit mode jobs to complete
2025/01/02 16:59:07 DEBUG: gocron: limitMode jobs completed
2025/01/02 16:59:07 DEBUG: gocron: executor stopped
2025/01/02 16:59:07 DEBUG: gocron: scheduler stopped
2025/01/02 16:59:07 DEBUG: Updating limit mode to: 2, limit: 5
==================
WARNING: DATA RACE
Write at 0x00c000722510 by goroutine 33291:
  github.com/go-co-op/gocron/v2.WithUpdateLimitMode.func1()
      /home/runner/work/gocron/gocron/scheduler.go:852 +0x38e
  github.com/go-co-op/gocron/v2.(*scheduler).UpdateScheduler()
      /home/runner/work/gocron/gocron/scheduler.go:807 +0x11c
  github.com/go-co-op/gocron/v2.TestScheduler_UpdateScheduler.func1()
      /home/runner/work/gocron/gocron/scheduler_test.go:2743 +0x381
  testing.tRunner()
      /opt/hostedtoolcache/go/1.20.14/x64/src/testing/testing.go:1576 +0x216
  testing.(*T).Run.func1()
      /opt/hostedtoolcache/go/1.20.14/x64/src/testing/testing.go:1629 +0x47

Previous read at 0x00c000722510 by goroutine 33293:
  github.com/go-co-op/gocron/v2.(*executor).stop()
      /home/runner/work/gocron/gocron/executor.go:530 +0x819
  github.com/go-co-op/gocron/v2.(*executor).start()
      /home/runner/work/gocron/gocron/executor.go:230 +0x7cf
  github.com/go-co-op/gocron/v2.(*scheduler).selectStart.func2()
      /home/runner/work/gocron/gocron/scheduler.go:494 +0x39

Goroutine 33291 (running) created at:
  testing.(*T).Run()
      /opt/hostedtoolcache/go/1.20.14/x64/src/testing/testing.go:1629 +0x805
  github.com/go-co-op/gocron/v2.TestScheduler_UpdateScheduler()
      /home/runner/work/gocron/gocron/scheduler_test.go:2729 +0x31d
  testing.tRunner()
      /opt/hostedtoolcache/go/1.20.14/x64/src/testing/testing.go:1576 +0x216
  testing.(*T).Run.func1()
      /opt/hostedtoolcache/go/1.20.14/x64/src/testing/testing.go:1629 +0x47

Goroutine 33293 (finished) created at:
  github.com/go-co-op/gocron/v2.(*scheduler).selectStart()
      /home/runner/work/gocron/gocron/scheduler.go:494 +0x109
  github.com/go-co-op/gocron/v2.NewScheduler.func1()
      /home/runner/work/gocron/gocron/scheduler.go:206 +0x804
==================
2025/01/02 16:59:07 DEBUG: Limit mode update completed
2025/01/02 16:59:07 DEBUG: gocron: scheduler starting
2025/01/02 16:59:07 INFO: gocron: scheduler started
2025/01/02 16:59:07 DEBUG: gocron: executor started
2025/01/02 16:59:07 DEBUG: gocron: stopping scheduler
2025/01/02 16:59:07 DEBUG: gocron: stopping executor
2025/01/02 16:59:07 DEBUG: gocron: waiting for singleton jobs to complete
2025/01/02 16:59:07 DEBUG: gocron: waiting for standard jobs to complete
2025/01/02 16:59:07 DEBUG: gocron: singleton jobs completed
2025/01/02 16:59:07 DEBUG: gocron: standard jobs completed
2025/01/02 16:59:07 DEBUG: gocron: waiting for limit mode jobs to complete
2025/01/02 16:59:07 DEBUG: gocron: limitMode jobs completed
2025/01/02 16:59:07 DEBUG: gocron: executor stopped
2025/01/02 16:59:07 DEBUG: gocron: scheduler stopped
    testing.go:1446: race detected during execution of test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants