using HybirdFrameworkCore.Entity;
using HybirdFrameworkCore.AutoTask;
using Microsoft.AspNetCore.Mvc;
namespace WebStarter.Controllers.System;
[Produces("application/json")]
[ApiController]
[Route("api/[controller]")]
public class TaskController
{
///
/// 获取任务列表
///
///
[HttpGet("/GetAll")]
public Result> GetAll()
{
List result = new();
foreach (var (key, value) in TaskInit.TaskMap)
{
result.Add(new TaskInfo()
{
Name = key,
Interval = value.Interval(),
Stoped = value.Stoped()
});
}
return Result>.Success(result);
}
///
/// 停止任务
///
///
///
[HttpGet("/stop/{taskName}")]
public Result Stop(string taskName)
{
if (TaskInit.TaskMap.TryGetValue(taskName, out var task))
{
task.Stop();
return Result.Success(task.Stoped());
}
return Result.Fail("任务不存在");
}
///
/// 启动任务
///
///
///
[HttpGet("/start/{taskName}")]
public Result Start(string taskName)
{
if (TaskInit.TaskMap.TryGetValue(taskName, out var task))
{
task.Start();
return Result.Success(task.Stoped());
}
return Result.Fail("任务不存在");
}
}