mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-14 08:58:27 +08:00
Go: add command, list, remove, stop tasks (#16190)
### What problem does this PR solve? ``` RAGFlow(admin)> stop user 'abc' ingestion tasks; +-----------------------------------+-------+--------------------------------------------------------------------------+-------+ | command | email | error | tasks | +-----------------------------------+-------+--------------------------------------------------------------------------+-------+ | stop_ingestion_tasks_by_condition | abc | 'Stop ingestion tasks by condition' is implemented in enterprise edition | | +-----------------------------------+-------+--------------------------------------------------------------------------+-------+ RAGFlow(admin)> stop user 'abc' ingestion tasks 'created; +-----------------------------------+-------+--------------------------------------------------------------------------+----------+-------+ | command | email | error | status | tasks | +-----------------------------------+-------+--------------------------------------------------------------------------+----------+-------+ | stop_ingestion_tasks_by_condition | abc | 'Stop ingestion tasks by condition' is implemented in enterprise edition | created; | | +-----------------------------------+-------+--------------------------------------------------------------------------+----------+-------+ RAGFlow(admin)> stop user 'abc' ingestion tasks 'create'; +-----------------------------------+-------+--------------------------------------------------------------------------+--------+-------+ | command | email | error | status | tasks | +-----------------------------------+-------+--------------------------------------------------------------------------+--------+-------+ | stop_ingestion_tasks_by_condition | abc | 'Stop ingestion tasks by condition' is implemented in enterprise edition | create | | +-----------------------------------+-------+--------------------------------------------------------------------------+--------+-------+ RAGFlow(admin)> remove user 'abc' ingestion tasks 'create'; +-------------------------------------+-------+----------------------------------------------------------------------------+--------+-------+ | command | email | error | status | tasks | +-------------------------------------+-------+----------------------------------------------------------------------------+--------+-------+ | remove_ingestion_tasks_by_condition | abc | 'Remove ingestion tasks by condition' is implemented in enterprise edition | create | | +-------------------------------------+-------+----------------------------------------------------------------------------+--------+-------+ RAGFlow(admin)> remove user 'abc' ingestion tasks; +-------------------------------------+-------+----------------------------------------------------------------------------+-------+ | command | email | error | tasks | +-------------------------------------+-------+----------------------------------------------------------------------------+-------+ | remove_ingestion_tasks_by_condition | abc | 'Remove ingestion tasks by condition' is implemented in enterprise edition | | +-------------------------------------+-------+----------------------------------------------------------------------------+-------+ ``` ### Type of change - [x] New Feature (non-breaking change which adds functionality) --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -138,6 +138,8 @@ func (p *Parser) parseAdminListCommand() (*Command, error) {
|
||||
return NewCommand("list_services"), nil
|
||||
case TokenUsers:
|
||||
return p.parseAdminListUsersCommand()
|
||||
case TokenUser:
|
||||
return p.parseAdminListUserCommand()
|
||||
case TokenRoles:
|
||||
p.nextToken()
|
||||
// Semicolon is optional for SHOW TOKEN
|
||||
@@ -383,26 +385,31 @@ func (p *Parser) parseAdminListIngestors() (*Command, error) {
|
||||
func (p *Parser) parseAdminStopIngestionTasks() (*Command, error) {
|
||||
p.nextToken() // consume STOP
|
||||
|
||||
if p.curToken.Type != TokenIngestion {
|
||||
return nil, fmt.Errorf("expected INGESTION")
|
||||
var cmd *Command
|
||||
|
||||
switch p.curToken.Type {
|
||||
case TokenIngestion:
|
||||
p.nextToken()
|
||||
if p.curToken.Type != TokenTasks {
|
||||
return nil, fmt.Errorf("expected TASKS")
|
||||
}
|
||||
p.nextToken() // consume TASK
|
||||
|
||||
taskString, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tasks := strings.Split(taskString, " ")
|
||||
p.nextToken() // consume TASK
|
||||
|
||||
cmd = NewCommand("admin_stop_ingestion_tasks")
|
||||
cmd.Params["tasks"] = tasks
|
||||
case TokenUser:
|
||||
return p.parseAdminStopUserCommand()
|
||||
default:
|
||||
return nil, fmt.Errorf("expected USER or INGESTION")
|
||||
}
|
||||
p.nextToken()
|
||||
|
||||
if p.curToken.Type != TokenTasks {
|
||||
return nil, fmt.Errorf("expected TASKS")
|
||||
}
|
||||
p.nextToken() // consume TASK
|
||||
|
||||
taskString, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tasks := strings.Split(taskString, " ")
|
||||
p.nextToken() // consume TASK
|
||||
|
||||
cmd := NewCommand("admin_stop_ingestion_tasks")
|
||||
cmd.Params["tasks"] = tasks
|
||||
|
||||
// Semicolon is optional for UNSET TOKEN
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
@@ -1901,6 +1908,8 @@ func (p *Parser) parseAdminRemoveCommand() (*Command, error) {
|
||||
cmd.Params["service_number"] = serviceNum
|
||||
case TokenIngestion:
|
||||
return p.parseAdminRemoveIngestionTasks()
|
||||
case TokenUser:
|
||||
return p.parseAdminRemoveUserCommand()
|
||||
default:
|
||||
return nil, fmt.Errorf("expected SERVICE")
|
||||
}
|
||||
@@ -2517,3 +2526,112 @@ commandLoop:
|
||||
}
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
// LIST USER 'user@example.com' INGESTION TASKS;
|
||||
func (p *Parser) parseAdminListUserCommand() (*Command, error) {
|
||||
p.nextToken() // consume USER
|
||||
|
||||
userName, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.nextToken()
|
||||
|
||||
var cmd *Command
|
||||
|
||||
switch p.curToken.Type {
|
||||
case TokenIngestion:
|
||||
p.nextToken()
|
||||
if p.curToken.Type != TokenTasks {
|
||||
return nil, fmt.Errorf("expected TASKS after INGESTION")
|
||||
}
|
||||
p.nextToken()
|
||||
cmd = NewCommand("admin_list_user_ingestion_tasks_command")
|
||||
if p.curToken.Type == TokenQuotedString {
|
||||
var status string
|
||||
status, err = p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cmd.Params["status"] = status
|
||||
p.nextToken()
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("expected INGESTION after USER")
|
||||
}
|
||||
|
||||
cmd.Params["user_name"] = userName
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
// STOP USER 'user@example.com' INGESTION TASKS 'created';
|
||||
func (p *Parser) parseAdminStopUserCommand() (*Command, error) {
|
||||
p.nextToken() // consume USER
|
||||
|
||||
userName, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.nextToken()
|
||||
|
||||
var cmd *Command
|
||||
switch p.curToken.Type {
|
||||
case TokenIngestion:
|
||||
p.nextToken()
|
||||
if p.curToken.Type != TokenTasks {
|
||||
return nil, fmt.Errorf("expected TASKS after INGESTION")
|
||||
}
|
||||
p.nextToken()
|
||||
cmd = NewCommand("admin_stop_user_ingestion_tasks_command")
|
||||
if p.curToken.Type == TokenQuotedString {
|
||||
var status string
|
||||
status, err = p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cmd.Params["status"] = status
|
||||
p.nextToken()
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("expected INGESTION after USER")
|
||||
}
|
||||
|
||||
cmd.Params["user_name"] = userName
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
// REMOVE USER 'user@example.com' INGESTION TASKS 'created';
|
||||
func (p *Parser) parseAdminRemoveUserCommand() (*Command, error) {
|
||||
p.nextToken() // consume USER
|
||||
|
||||
userName, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.nextToken()
|
||||
|
||||
var cmd *Command
|
||||
switch p.curToken.Type {
|
||||
case TokenIngestion:
|
||||
p.nextToken()
|
||||
if p.curToken.Type != TokenTasks {
|
||||
return nil, fmt.Errorf("expected TASKS after INGESTION")
|
||||
}
|
||||
p.nextToken()
|
||||
cmd = NewCommand("admin_remove_user_ingestion_tasks_command")
|
||||
if p.curToken.Type == TokenQuotedString {
|
||||
var status string
|
||||
status, err = p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cmd.Params["status"] = status
|
||||
p.nextToken()
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("expected INGESTION after USER")
|
||||
}
|
||||
|
||||
cmd.Params["user_name"] = userName
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user