Files

30 lines
941 B
Go

package application
import (
"context"
"time"
"git.cin.su/m/Assistant/contracts/work"
"git.cin.su/m/Assistant/modules/work/domain"
"git.cin.su/m/Assistant/modules/work/ports"
)
func ExecuteDryRunDispatch(ctx context.Context, store ports.ExecutionStore, intent work.AgentDispatchIntent, workerID string, token work.AgentFencingToken, now time.Time, ttl time.Duration) (work.DryRunDispatch, error) {
dispatch, err := domain.BuildDryRunDispatch(intent, workerID, token, now, ttl)
if err != nil {
return work.DryRunDispatch{}, err
}
if err := store.SaveDispatchIntent(ctx, dispatch.Intent); err != nil {
return work.DryRunDispatch{}, err
}
if err := store.SaveAgentLease(ctx, dispatch.Lease); err != nil {
return work.DryRunDispatch{}, err
}
for _, callback := range dispatch.Callbacks {
if err := store.AcceptAgentCallback(ctx, callback); err != nil {
return work.DryRunDispatch{}, err
}
}
return dispatch, nil
}