Files
tasks/chasm/lib/scheduler/scheduler_tasks.go
Lina JodoinandGitHub f2f90fbba4 [Scheduled Actions] CHASM API Handlers (#8474)
## What changed?
- Added an RPC service to the CHASM Scheduler which implements its CRUD
operations.
- The intention is for the frontend handler to attempt to route to CHASM
operations in history, and in the event of a not-found, let frontend
retry its
old (V1 scheduler) path.
- These assume frontend's validation. As we move towards ripping out the
old
scheduler code, we'll start moving all of that existing logic over into
the CHASM
world, but for now, let's keep it as-is for as light a possible touch on
existing
paths.
- This is based on `standalone-activity` just to get the API boilerplate
stuff.
2025-10-24 18:14:31 +00:00

54 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 {
config *Config
}
func NewSchedulerIdleTaskExecutor(opts SchedulerIdleTaskExecutorOptions) *SchedulerIdleTaskExecutor {
return &SchedulerIdleTaskExecutor{
config: opts.Config,
}
}
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,
taskAttrs chasm.TaskAttributes,
task *schedulerpb.SchedulerIdleTask,
) (bool, error) {
idleTimeTotal := task.IdleTimeTotal.AsDuration()
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(taskAttrs.ScheduledTime) != 0 {
return false, nil
}
return !scheduler.Closed, nil
}