Files
tasks/chasm/lib/scheduler/scheduler_tasks.go
Lina JodoinandGitHub 4c140933cf [Scheduled Actions] CHASM Scheduler (#8255)
## 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.
2025-09-02 19:50:45 +00:00

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
}