Question

I am using FluentScheduler, and have an issue where I have 2 Registry classes,

FeedRegistry
SitemapRegistry

FeedRegistry is supposed to run every 15min, and sitemapregistry evey 6 hours.

I have this code:

 TaskManager.Initialize(new FeedRegistry());
 TaskManager.Initialize(new SitemapRegistry());

And

Schedule<FeedTask>().ToRunNow().AndEvery(15).Minutes();
Schedule<SitemapTask>().ToRunNow().AndEvery(6).Hours();

SitemapTask

    public class SitemapTask : ITask
    {
        private readonly ISitemapHelper _sitemapHelper;

        public SitemapTask(ISitemapHelper  sitemapHelper)
        {
            _sitemapHelper = sitemapHelper;
        }

        public void Execute()
        {
                _sitemapHelper.Process(false);
        }
    }

FeedTask

    public class FeedTask : ITask
    {
        private readonly IFeedHelper _feedHelper;

        public FeedTask(IFeedHelper feedHelper)
        {
            _feedHelper = feedHelper;
        }

        public void Execute()
        {
            _feedHelper.Process(false);
        }
    }

I am using Autofac and the dependencies have been registered as "InstancePerLifetimeScope". The problem is FeedTask will run only once when the application begins but will not run again after 15minutes. However if I reverse the Initializations like

Schedule<SitemapTask>().ToRunNow().AndEvery(6).Hours();
Schedule<FeedTask>().ToRunNow().AndEvery(15).Minutes();

It will run every 15minutes (and I assume the sitemap will not run every 6 hours)

How to fix?

Was it helpful?

Solution

I had the same problem and I noticed that we cannot initialize multiple registries.

But, instead, we can initialize one registry that starts multiple schedules.

Following is an example of what I did.

protected void Application_Start()
{
    TaskManager.TaskFactory = new StructureMapTaskFactory();
    TaskManager.Initialize(new RegistryMultipleTasks());
}

public class RegistryMultipleTasks : Registry
{
    public RegistryMultipleTasks()
    {
        FeedRegistry.AddSchedule(this);
        SitemapRegistry.AddSchedule(this);
    }
}

public class FeedRegistry
{
    public static void AddSchedule(Registry registry = null)
    {
        registry.Schedule(() => FeedTask()).ToRunNow().AndEvery(15).Minutes();
    }

    private static void FeedTask()
    {
        // TODO
    }
}

This worked for me.

PS: I know this is an old thread, but I am writing this with the purpose of helping anyone in the same problem.

OTHER TIPS

I'm not too familiar with FluentScheduler, but just from reading this page, I'd suspect something is throwing an exception. Try adding an event handler for errors and seeing if any are occurring.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top