dotnet-labs / ServiceWorkerCronJob

Schedule Cron Jobs using HostedService in ASP.NET Core
MIT License
265 stars 71 forks source link

Multiple CronJobs with same object of class #3

Closed markofranjic closed 4 years ago

markofranjic commented 4 years ago

Hi Chan,

Could you please give me information if I can run more then one background jobs with same object of class. For example. I need to run job at 21:00 and same job need to be run at 05:00?

I have tried ` services.AddCronJob(c => { c.TimeZoneInfo = TimeZoneInfo.Local; c.CronExpression = @"{21:00 Time Example}"; });

        services.AddCronJob<MyCronJob>(c =>
        {
            c.TimeZoneInfo = TimeZoneInfo.Local;
            c.CronExpression = @"{05:00 Time Example}";
        });`

Regards

changhuixu commented 4 years ago

Hi @markofranjic It's a question about CRON expression. You can use the following configuration.

services.AddCronJob<MyCronJob>(c =>
{
     c.TimeZoneInfo = TimeZoneInfo.Local;
     c.CronExpression = @"0 5,21 * * *";
});

I did a preliminary test, and it worked. You should test on your own. Let me know what you find out.