Files
ragflow/internal/ingestion/task/task_handler.go
Jack 7db39822db Feature: user select pipeline support (#16788)
### Summary

Feature: user select pipeline support
2026-07-10 14:30:28 +08:00

91 lines
2.3 KiB
Go

//
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package task
import (
"context"
"fmt"
"strings"
)
// TaskHandler dispatches document processing tasks by task_type.
// Mirrors Python task_handler.py:handle().
type TaskHandler struct {
ctx *TaskContext
newDataflowService func(ctx *TaskContext, dataflowID string) (*PipelineExecutor, error)
}
// NewTaskHandler creates a TaskHandler for the given task context.
func NewTaskHandler(ctx *TaskContext) *TaskHandler {
return &TaskHandler{
ctx: ctx,
newDataflowService: func(ctx *TaskContext, dataflowID string) (*PipelineExecutor, error) {
return NewDataflowService(ctx, dataflowID, 0, 0)
},
}
}
func (h *TaskHandler) WithDataflowServiceFactory(factory func(ctx *TaskContext, dataflowID string) (*PipelineExecutor, error)) *TaskHandler {
h.newDataflowService = factory
return h
}
// Handle routes the task by type and executes the appropriate handler.
func (h *TaskHandler) Handle() error {
if h.ctx == nil {
return fmt.Errorf("task handler: nil context")
}
return h.handleDataflow()
}
func (h *TaskHandler) handleMemory() error {
return nil // stub
}
func (h *TaskHandler) handleDataflow() error {
dataflowID := ""
if strings.Trim(h.ctx.PipelineID, " ") != "" {
dataflowID = h.ctx.PipelineID
}
svc, err := h.newDataflowService(h.ctx, dataflowID)
if err != nil {
return err
}
runCtx := h.ctx.Ctx
if runCtx == nil {
runCtx = context.Background()
}
return svc.Execute(runCtx)
}
func (h *TaskHandler) handleRaptor() error {
return nil // stub
}
func (h *TaskHandler) handleGraphRAG() error {
return nil // stub
}
func (h *TaskHandler) handleStub(name string) error {
return nil
}
func (h *TaskHandler) handleStandard() error {
return nil // stub
}