1

please give me some advice.

My problem is the following, I'm implementing a dependency in a custom scheduled task. The task itself is initialized with the necessary dependency, however, during the start, the task is transferred to the status Is Running, but the code is not executed

ScheduledTask:

 public class TestJob : ScheduledTask, IJob
{
    private readonly ITestService _testService;

    public TestJob(ITestService service)
    {
        if (service is null)
        {
            throw new ArgumentException(nameof(service));
        }

        _testService = service;

    }
    public override void ExecuteTask()
    {
        _testService.DoSomting("From job");
    }

    public override string TaskName
    {
        get
        {
            return this.GetType().FullName;
        }
    }

TestService

public interface ITestService
{
    void DoSomting();
    void DoSomting(string message);
}


 public class TestService : ITestService
{
    public void DoSomting()
    {
        LogHelper.Logger().Information("======> Somting happined");
    }

    public void DoSomting(string message)
    {
        LogHelper.Logger().Information($"======> Somting happined {message}");
    }
}

regestry

        private void CreateJob<T>(SchedulingManager manager, string appSettingsName)
        where T : ScheduledTask
    {
        try
        {

            var job = ObjectFactory.Resolve<T>();
            var newUsersAddingJobSettings = settings_eg;

            job.Id = Guid.NewGuid();
            job.Title = job.TaskName;
            job.ScheduleSpecType = settings_eg[0];
            job.ScheduleSpec = settings_eg[1];
            job.ExecuteTime = CrontabHelper.GetExecuteTime(nsettings_eg);
            manager.AddTask(job);
            manager.SaveChanges();

        }
        catch (Exception e)
        {
            ////
        }
    }

Registration of the service in ninjet

ObjectFactory.Container.RegisterType<ITestService, TestService>();
Sky
  • 11
  • 1
  • Are you saying that the task is successfully added to the DB (sf_scheduled_tasks table) but when it runs, it does not go to the ExecuteTask method at all? – Veselin Vasilev Oct 08 '21 at 04:03

0 Answers0