Scheduling multiple Quartz jobs in Topshelf
Asked Answered
T

2

5

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);                       
        });       
    }
Tosspot answered 22/1, 2014 at 21:46 Comment(1)
Can't you put the Quartz initialization inside your service class Start() and shutdown on Stop() methods? Why use this integration at all?Stagestruck
A
4

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.

Afforest answered 22/1, 2014 at 23:42 Comment(0)
G
8

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

Glaciology answered 28/1, 2014 at 20:15 Comment(2)
x.SchedulQuartzJob (extension) does not exist in HostConfigurator, can you show me how did you do it?Fungous
@Fungous ScheduleQuartzJob is in the library TopShelf.QuartzGenie
A
4

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.

Afforest answered 22/1, 2014 at 23:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.