Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scheduling multiple Quartz jobs in Topshelf

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);                       
        });       
    }
like image 854
Jay Sun Avatar asked Jan 22 '14 21:01

Jay Sun


2 Answers

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

like image 124
Dexterity Avatar answered Oct 08 '22 20:10

Dexterity


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.

like image 43
Travis Avatar answered Oct 08 '22 20:10

Travis