mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed? - Merge PR combining the previous PRs: #8164, #8165, #8166, #8167, #8168, #8169 ## Why? - All of those PRs are interdependent and cannot be merged individually cleanly. Sending a single merge commit PR to be merged to main. ## How did you test it? - [ ] built - [ ] run locally and tested manually - [ ] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s) ## Potential risks - It's still disabled.
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package scheduler
|
|
|
|
import (
|
|
"time"
|
|
|
|
"go.temporal.io/server/chasm"
|
|
"go.temporal.io/server/chasm/lib/scheduler/gen/schedulerpb/v1"
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
type SchedulerIdleTaskExecutorOptions struct {
|
|
fx.In
|
|
|
|
Config *Config
|
|
}
|
|
|
|
type SchedulerIdleTaskExecutor struct {
|
|
SchedulerIdleTaskExecutorOptions
|
|
}
|
|
|
|
func NewSchedulerIdleTaskExecutor(opts SchedulerIdleTaskExecutorOptions) *SchedulerIdleTaskExecutor {
|
|
return &SchedulerIdleTaskExecutor{opts}
|
|
}
|
|
|
|
func (r *SchedulerIdleTaskExecutor) Execute(
|
|
ctx chasm.MutableContext,
|
|
scheduler *Scheduler,
|
|
_ chasm.TaskAttributes,
|
|
_ *schedulerpb.SchedulerIdleTask,
|
|
) error {
|
|
scheduler.Closed = true
|
|
return nil
|
|
}
|
|
|
|
func (r *SchedulerIdleTaskExecutor) Validate(
|
|
ctx chasm.Context,
|
|
scheduler *Scheduler,
|
|
task chasm.TaskAttributes,
|
|
_ *schedulerpb.SchedulerIdleTask,
|
|
) (bool, error) {
|
|
idleTimeTotal := r.Config.Tweakables(scheduler.Namespace).IdleTime
|
|
idleExpiration, isIdle := scheduler.getIdleExpiration(ctx, idleTimeTotal, time.Time{})
|
|
|
|
// If the scheduler has since woken up, or its idle expiration time changed, this
|
|
// task must be obsolete.
|
|
if !isIdle || idleExpiration.Compare(task.ScheduledTime) != 0 {
|
|
return false, nil
|
|
}
|
|
|
|
return !scheduler.Closed, nil
|
|
}
|