using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Quartz;
namespace SlnMesnac.Controllers
{
///
/// 任务调度
///
[ApiController]
[Route("api/[controller]")]
public class JobController
{
private readonly IScheduler _scheduler;
///
///
///
///
public JobController(IScheduler scheduler)
{
_scheduler = scheduler;
}
///
/// 启动任务
///
/// 任务名称
/// 任务分组
///
[HttpPost("start")]
public async Task StartJob(string jobName, string groupName)
{
// 检查调度器是否已经启动
if (!_scheduler.IsStarted)
{
await _scheduler.Start();
}
var myJobKey = new JobKey(jobName, groupName);
await _scheduler.ResumeJob(myJobKey);
return "Job started successfully.";
}
///
/// 停止任务
///
/// 任务名称
/// 任务分组
///
[HttpPost("stop")]
public async Task StopJob(string jobName, string groupName)
{
var myJobKey = new JobKey(jobName, groupName);
await _scheduler.PauseJob(myJobKey);
return "Job stopped successfully.";
}
}
}