mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## 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.
54 lines
1.2 KiB
Go
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
|
|
}
|