I want a way to trigger a scheduled task by code. Instead of using the refresh=true url. That url creates a webrequest and it gets a timeout.
So I want to make it possible with our own url to get the scheduled task and say: start in 2 minutes.
Maybe you could try something like this (I just stuck in a test controller):
using Litium.Application.Runtime;
using Litium.Foundation.Security;
using Litium.Scheduler;
using Litium.Web.Products.PriceAgents;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
using System.Web.Mvc;
namespace Litium.Accelerator.Mvc.Controllers
{
public class TestController : LitiumController
{
private readonly SchedulerService _schedulerService;
public TestController(SchedulerService schedulerService)
{
_schedulerService = schedulerService;
}
public ActionResult Index()
{
_schedulerService.ScheduleJob<ExecutePriceAgentTask>(x => x.Run(), new ScheduleJobArgs { ExecuteAt = DateTime.Now.AddMinutes(2) });
return new EmptyResult();
}
}
public class ExecutePriceAgentTask
{
private readonly ILogger<IPriceAgentItemFactory> _logger;
private readonly RollingFileService _rollingFileService;
public ExecutePriceAgentTask(
ILogger<IPriceAgentItemFactory> logger,
RollingFileService rollingFileService)
{
_logger = logger;
_rollingFileService = rollingFileService;
}
public Task Run()
{
var priceAgentScheduler = new PriceAgentScheduler(_logger, _rollingFileService);
priceAgentScheduler.ExecuteTask(SecurityToken.CurrentSecurityToken, null);
return Task.CompletedTask;
}
}
}