Complete batch import v2 runtime and host capability recovery
This commit is contained in:
@@ -55,11 +55,14 @@ func (r batchImportRuntimeRunner) execute(ctx context.Context) (BatchImportRunCr
|
||||
}
|
||||
|
||||
if _, err := service.StartRun(ctx, batch.BatchImportRunRequest{
|
||||
RunID: runID,
|
||||
Mode: r.request.Mode,
|
||||
AccessMode: r.request.AccessMode,
|
||||
HostID: r.hostRow.HostID,
|
||||
Entries: entries,
|
||||
RunID: runID,
|
||||
Mode: r.request.Mode,
|
||||
AccessMode: r.request.AccessMode,
|
||||
HostID: r.hostRow.HostID,
|
||||
SubscriptionUsers: append([]string(nil), r.request.SubscriptionUsers...),
|
||||
SubscriptionDays: r.request.SubscriptionDays,
|
||||
ProbeAPIKey: r.request.ProbeAPIKey,
|
||||
Entries: entries,
|
||||
}); err != nil {
|
||||
return BatchImportRunCreateResponse{}, err
|
||||
}
|
||||
@@ -89,7 +92,14 @@ func (r batchImportRuntimeRunner) advanceRun(ctx context.Context, runID string)
|
||||
if timeout <= 0 {
|
||||
timeout = time.Second
|
||||
}
|
||||
deadline := time.Now().Add(timeout)
|
||||
return r.driveRun(ctx, runID, timeout)
|
||||
}
|
||||
|
||||
func (r batchImportRuntimeRunner) driveRun(ctx context.Context, runID string, waitBudget time.Duration) error {
|
||||
deadline := time.Now()
|
||||
if waitBudget > 0 {
|
||||
deadline = deadline.Add(waitBudget)
|
||||
}
|
||||
|
||||
worker := batch.ConfirmationWorker{
|
||||
WorkerID: "batch-import-api",
|
||||
@@ -137,7 +147,7 @@ func (r batchImportRuntimeRunner) advanceRun(ctx context.Context, runID string)
|
||||
if run.TotalItems > 0 && run.CompletedItems >= run.TotalItems {
|
||||
return nil
|
||||
}
|
||||
if !pendingWork || !time.Now().Before(deadline) {
|
||||
if !pendingWork || waitBudget <= 0 || !time.Now().Before(deadline) {
|
||||
return nil
|
||||
}
|
||||
if err := sleepWithContext(ctx, batchImportRetryDelay); err != nil {
|
||||
@@ -274,6 +284,17 @@ func (s batchImportRunItemStore) Upsert(ctx context.Context, item sqlite.ImportR
|
||||
return s.store.ImportRunItems().Upsert(ctx, item)
|
||||
}
|
||||
|
||||
func (s batchImportRunItemStore) TryAcquireLease(ctx context.Context, itemID, workerID string, now time.Time, leaseDuration time.Duration) (sqlite.ImportRunItem, bool, error) {
|
||||
item, claimed, err := s.store.ImportRunItems().TryAcquireConfirmationLease(ctx, itemID, workerID, now, leaseDuration)
|
||||
if err != nil || !claimed {
|
||||
return item, claimed, err
|
||||
}
|
||||
if item.RunID != s.runID {
|
||||
return sqlite.ImportRunItem{}, false, nil
|
||||
}
|
||||
return item, true, nil
|
||||
}
|
||||
|
||||
func generatedBatchImportPack(providerManifest pack.ProviderManifest) pack.LoadedPack {
|
||||
return pack.LoadedPack{
|
||||
Manifest: pack.Manifest{
|
||||
|
||||
Reference in New Issue
Block a user