feat(work): orchestrate dry-run dispatch persistence
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package ports
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/work"
|
||||
)
|
||||
|
||||
type ExecutionStore interface {
|
||||
SaveDispatchIntent(context.Context, work.AgentDispatchIntent) error
|
||||
SaveAgentLease(context.Context, work.AgentLease) error
|
||||
AcceptAgentCallback(context.Context, work.AgentCallback) error
|
||||
}
|
||||
Reference in New Issue
Block a user