mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed? Added a return flag on the NewExecution function to indicate if a new execution was actually created. Also added docs to NewExecution. Changed standalone activity on start to pass back started flag if new exec was actually created. ## Why? On NewExecution today if we use BusinessIDConflictPolicyUseExisting, we need a way to distinguish whether something is newly created or not. Based on that flag, caller code can react differently. For standalone activity, we must pass back the started flag according to whether a new exec was actually started, to matching existing workflow behavior. ## How did you test it? - [X] built - [X] run locally and tested manually - [X] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s) --------- Co-authored-by: Yichao Yang <[email protected]>
105 lines
2.5 KiB
Go
105 lines
2.5 KiB
Go
package scheduler
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.temporal.io/server/chasm"
|
|
"go.temporal.io/server/chasm/lib/scheduler/gen/schedulerpb/v1"
|
|
"go.temporal.io/server/common/log"
|
|
)
|
|
|
|
type handler struct {
|
|
schedulerpb.UnimplementedSchedulerServiceServer
|
|
|
|
logger log.Logger
|
|
}
|
|
|
|
func newHandler(logger log.Logger) *handler {
|
|
return &handler{
|
|
logger: logger,
|
|
}
|
|
}
|
|
|
|
func (h *handler) CreateSchedule(ctx context.Context, req *schedulerpb.CreateScheduleRequest) (resp *schedulerpb.CreateScheduleResponse, err error) {
|
|
defer log.CapturePanic(h.logger, &err)
|
|
|
|
result, err := chasm.NewExecution(
|
|
ctx,
|
|
chasm.ExecutionKey{
|
|
NamespaceID: req.NamespaceId,
|
|
BusinessID: req.FrontendRequest.ScheduleId,
|
|
},
|
|
CreateScheduler,
|
|
req,
|
|
chasm.WithRequestID(req.FrontendRequest.RequestId),
|
|
)
|
|
return result.Output, err
|
|
}
|
|
|
|
func (h *handler) UpdateSchedule(ctx context.Context, req *schedulerpb.UpdateScheduleRequest) (resp *schedulerpb.UpdateScheduleResponse, err error) {
|
|
defer log.CapturePanic(h.logger, &err)
|
|
|
|
resp, _, err = chasm.UpdateComponent(
|
|
ctx,
|
|
chasm.NewComponentRef[*Scheduler](
|
|
chasm.ExecutionKey{
|
|
NamespaceID: req.NamespaceId,
|
|
BusinessID: req.FrontendRequest.ScheduleId,
|
|
},
|
|
),
|
|
(*Scheduler).Update,
|
|
req,
|
|
)
|
|
return resp, err
|
|
}
|
|
|
|
func (h *handler) PatchSchedule(ctx context.Context, req *schedulerpb.PatchScheduleRequest) (resp *schedulerpb.PatchScheduleResponse, err error) {
|
|
defer log.CapturePanic(h.logger, &err)
|
|
|
|
resp, _, err = chasm.UpdateComponent(
|
|
ctx,
|
|
chasm.NewComponentRef[*Scheduler](
|
|
chasm.ExecutionKey{
|
|
NamespaceID: req.NamespaceId,
|
|
BusinessID: req.FrontendRequest.ScheduleId,
|
|
},
|
|
),
|
|
(*Scheduler).Patch,
|
|
req,
|
|
)
|
|
return resp, err
|
|
}
|
|
|
|
func (h *handler) DeleteSchedule(ctx context.Context, req *schedulerpb.DeleteScheduleRequest) (resp *schedulerpb.DeleteScheduleResponse, err error) {
|
|
defer log.CapturePanic(h.logger, &err)
|
|
|
|
resp, _, err = chasm.UpdateComponent(
|
|
ctx,
|
|
chasm.NewComponentRef[*Scheduler](
|
|
chasm.ExecutionKey{
|
|
NamespaceID: req.NamespaceId,
|
|
BusinessID: req.FrontendRequest.ScheduleId,
|
|
},
|
|
),
|
|
(*Scheduler).Delete,
|
|
req,
|
|
)
|
|
return resp, err
|
|
}
|
|
|
|
func (h *handler) DescribeSchedule(ctx context.Context, req *schedulerpb.DescribeScheduleRequest) (resp *schedulerpb.DescribeScheduleResponse, err error) {
|
|
defer log.CapturePanic(h.logger, &err)
|
|
|
|
return chasm.ReadComponent(
|
|
ctx,
|
|
chasm.NewComponentRef[*Scheduler](
|
|
chasm.ExecutionKey{
|
|
NamespaceID: req.NamespaceId,
|
|
BusinessID: req.FrontendRequest.ScheduleId,
|
|
},
|
|
),
|
|
(*Scheduler).Describe,
|
|
req,
|
|
)
|
|
}
|