Question

Reading the documentation for Topshelf integrations here: https://github.com/dtinteractive/Topshelf.Integrations

And it seems like it should be as simple as scheduling multiple quartz jobs within the HostFactory but it looks like the second scheduled job is the only one that's running.

I'm not really sure how to proceed from here. But I need to schedule two jobs that run on different schedules. The first is supposed to be run daily while the second gets run hourly.

static void Main(string[] args)
    {
        HostFactory.Run(x =>                                 
        {
            x.ScheduleQuartzJobAsService(q =>
                q.WithJob(() => JobBuilder.Create<TmsIdImportTask>().Build())
                    .AddTrigger(() =>
                        TriggerBuilder.Create()
                            .WithSimpleSchedule(builder => builder
                                .WithIntervalInMinutes(Int32.Parse(ConfigurationManager.AppSettings["ScheduleImportFrequencyInMinutes"]))
                                .RepeatForever()).Build())
            );

            x.ScheduleQuartzJobAsService(q =>
                q.WithJob(() => JobBuilder.Create<ImportTmsXMLTask>().Build())
                    .AddTrigger(() => TriggerBuilder.Create().WithSimpleSchedule(builder =>
                        builder.WithIntervalInMinutes(Int32.Parse(ConfigurationManager.AppSettings["TMSImportFrequencyInMinutes"]))
                        .RepeatForever()).Build())
                        );


            x.RunAsLocalSystem();

            var description = ConfigurationManager.AppSettings["ServiceDescription"];
            x.SetDescription(description);

            var displayName = ConfigurationManager.AppSettings["ServiceDisplayName"];
            x.SetDisplayName(displayName);

            var serviceName = ConfigurationManager.AppSettings["ServiceName"];
            x.SetServiceName(serviceName);                       
        });       
    }
Was it helpful?

Solution 2

Create a second service or punt on the Topshelf-Quartz integration and have a service that initializes both Quartz instances and will shut them down.

Topshelf will only host a single [service] process, by design. You can't manage or monitor stuff to any useful degree if Topshelf is hosting multiple processes. It just ends up being an unsustainable pattern.

OTHER TIPS

I believe the reason you are having an issue is because you're using

x.ScheduleQuartzJobAsService

instead of

x.ScheduleQuartzJob

I'm just using Quartz for the first time, but I have like 20 different schedules running all within the same host

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