Complete batch import v2 runtime and host capability recovery
This commit is contained in:
@@ -42,9 +42,15 @@ type ListBatchImportRunsRequest struct {
|
||||
State string
|
||||
AccessMode string
|
||||
Query string
|
||||
Cursor string
|
||||
Limit int
|
||||
}
|
||||
|
||||
type ListBatchImportRunsResponse struct {
|
||||
Runs []batch.RunSummaryProjection `json:"runs"`
|
||||
NextCursor *string `json:"next_cursor"`
|
||||
}
|
||||
|
||||
type ListBatchImportRunItemsRequest struct {
|
||||
RunID string
|
||||
CurrentStage string
|
||||
@@ -55,9 +61,15 @@ type ListBatchImportRunItemsRequest struct {
|
||||
MatchedAccountState string
|
||||
AccountResolution string
|
||||
Query string
|
||||
Cursor string
|
||||
Limit int
|
||||
}
|
||||
|
||||
type ListBatchImportRunItemsResponse struct {
|
||||
Items []batch.ItemSummaryProjection `json:"items"`
|
||||
NextCursor *string `json:"next_cursor"`
|
||||
}
|
||||
|
||||
type GetBatchImportRunItemRequest struct {
|
||||
RunID string
|
||||
ItemID string
|
||||
@@ -85,7 +97,7 @@ func handleCreateBatchImportRun(w http.ResponseWriter, r *http.Request, fn func(
|
||||
writeJSON(w, http.StatusOK, result)
|
||||
}
|
||||
|
||||
func handleListBatchImportRuns(w http.ResponseWriter, r *http.Request, fn func(context.Context, ListBatchImportRunsRequest) ([]batch.RunSummaryProjection, error)) {
|
||||
func handleListBatchImportRuns(w http.ResponseWriter, r *http.Request, fn func(context.Context, ListBatchImportRunsRequest) (ListBatchImportRunsResponse, error)) {
|
||||
if fn == nil {
|
||||
writeHTTPError(w, &httpError{StatusCode: http.StatusInternalServerError, Code: "server_misconfigured", Message: "list-batch-import-runs action is not configured"})
|
||||
return
|
||||
@@ -94,16 +106,17 @@ func handleListBatchImportRuns(w http.ResponseWriter, r *http.Request, fn func(c
|
||||
State: strings.TrimSpace(r.URL.Query().Get("state")),
|
||||
AccessMode: strings.TrimSpace(r.URL.Query().Get("access_mode")),
|
||||
Query: strings.TrimSpace(r.URL.Query().Get("q")),
|
||||
Cursor: strings.TrimSpace(r.URL.Query().Get("cursor")),
|
||||
Limit: parsePositiveInt(r.URL.Query().Get("limit")),
|
||||
})
|
||||
if err != nil {
|
||||
writeHTTPError(w, classifyError(err))
|
||||
return
|
||||
}
|
||||
if result == nil {
|
||||
result = []batch.RunSummaryProjection{}
|
||||
if result.Runs == nil {
|
||||
result.Runs = []batch.RunSummaryProjection{}
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"runs": result})
|
||||
writeJSON(w, http.StatusOK, result)
|
||||
}
|
||||
|
||||
func buildCreateBatchImportRunAction(sqliteDSN string) func(context.Context, CreateBatchImportRunRequest) (BatchImportRunCreateResponse, error) {
|
||||
@@ -128,33 +141,63 @@ func buildCreateBatchImportRunAction(sqliteDSN string) func(context.Context, Cre
|
||||
}
|
||||
}
|
||||
|
||||
func buildListBatchImportRunsAction(sqliteDSN string) func(context.Context, ListBatchImportRunsRequest) ([]batch.RunSummaryProjection, error) {
|
||||
return func(ctx context.Context, req ListBatchImportRunsRequest) ([]batch.RunSummaryProjection, error) {
|
||||
func buildListBatchImportRunsAction(sqliteDSN string) func(context.Context, ListBatchImportRunsRequest) (ListBatchImportRunsResponse, error) {
|
||||
return func(ctx context.Context, req ListBatchImportRunsRequest) (ListBatchImportRunsResponse, error) {
|
||||
store, err := sqlite.Open(ctx, sqliteDSN)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return ListBatchImportRunsResponse{}, err
|
||||
}
|
||||
defer store.Close()
|
||||
|
||||
runs, err := store.ImportRuns().List(ctx, defaultPositiveInt(req.Limit, 50))
|
||||
runs, err := store.ImportRuns().List(ctx, 1000)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return ListBatchImportRunsResponse{}, err
|
||||
}
|
||||
|
||||
result := make([]batch.RunSummaryProjection, 0, len(runs))
|
||||
limit := defaultPositiveInt(req.Limit, 50)
|
||||
result := make([]batch.RunSummaryProjection, 0, limit)
|
||||
nextCursor := (*string)(nil)
|
||||
started := strings.TrimSpace(req.Cursor) == ""
|
||||
for _, run := range runs {
|
||||
if !started {
|
||||
if run.RunID == strings.TrimSpace(req.Cursor) {
|
||||
started = true
|
||||
}
|
||||
continue
|
||||
}
|
||||
if req.State != "" && run.State != req.State {
|
||||
continue
|
||||
}
|
||||
if req.AccessMode != "" && run.AccessMode != req.AccessMode {
|
||||
continue
|
||||
}
|
||||
if req.Query != "" && !strings.Contains(strings.ToLower(run.RunID), strings.ToLower(req.Query)) {
|
||||
continue
|
||||
if req.Query != "" {
|
||||
query := strings.ToLower(req.Query)
|
||||
if !strings.Contains(strings.ToLower(run.RunID), query) {
|
||||
items, err := store.ImportRunItems().ListByRunID(ctx, run.RunID)
|
||||
if err != nil {
|
||||
return ListBatchImportRunsResponse{}, err
|
||||
}
|
||||
matched := false
|
||||
for _, item := range items {
|
||||
if strings.Contains(strings.ToLower(item.ProviderID), query) || strings.Contains(strings.ToLower(item.BaseURL), query) {
|
||||
matched = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !matched {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(result) >= limit {
|
||||
cursor := run.RunID
|
||||
nextCursor = &cursor
|
||||
break
|
||||
}
|
||||
result = append(result, batch.ProjectRunSummary(run))
|
||||
}
|
||||
return result, nil
|
||||
return ListBatchImportRunsResponse{Runs: result, NextCursor: nextCursor}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user