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

[FEATURE] - Dynamic duration #731

Open
babyfish-ct opened this issue May 16, 2024 · 0 comments
Open

[FEATURE] - Dynamic duration #731

babyfish-ct opened this issue May 16, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@babyfish-ct
Copy link

babyfish-ct commented May 16, 2024

Add a function like SetNextDuration into Job, which can change the duration of the current job for next execution. the duration of the current job will be automatically reset after next execution.

For example

s, _ := NewScheduler()
defer func() { _ = s.Shutdown() }()

job, _ = s.NewJob(
	DurationJob(
	        // 1. Default behavior: Short waiting
		time.Second, 
	),
	NewTask(
		func() {
		    tasks := taskRepository.FetchBatch(100)
		    if len(tasks) == 0 {
		        // 2. Conditional behavior: Long waiting
		        job.SetNextDuration(time.Minute) 
		    }
		    taskExectuor.Execute(tasks)
		},
	),
)

That means:If there are some tasks, there is a short break (1 second) between each execution; If there are no tasks, there is a longer break between each execution (1 minute).

@babyfish-ct babyfish-ct added the enhancement New feature or request label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant