-1

現在、Hangfireを使って定期的にバックグラウンド処理を動かしているのですが、
RecurringJobによる定期実行処理だと最小が1分間隔になります。

RecurringJob.AddOrUpdate(
    () => Console.WriteLine("Recurring!"),
    Cron.Minutely);

秒単位(例えば10秒間隔)で動かしたいのですが、良い方法はありますでしょうか。
豊富な管理コンソールが魅力なので出来ればこのままHangfireを活用したいのですが、似たような使い方が出来るサービスがあればそれでもかまいません。

宜しくお願い致します。

2 件の回答 2

0

Quartz Enterprise Scheduler .NET
https://www.quartz-scheduler.net/

Quartz.NET 3.0は、現時点でAlpha版ですがCore対応・秒単位の定期実行があり合いそうです。(試したことは無いです。)

「Build a trigger for a specific moment in time, then repeating every ten seconds ten times」のサンプルが参考になります。
https://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/simpletriggers.html

trigger = TriggerBuilder.Create()
    .WithIdentity("trigger3", "group1")
    .StartAt(myTimeToStartFiring) // if a start time is not given (if this line were omitted), "now" is implied
    .WithSimpleSchedule(x => x
        .WithIntervalInSeconds(10)
        .WithRepeatCount(10)) // note that 10 repeats will give a total of 11 firings
    .ForJob(myJob) // identify job with handle to its JobDetail itself                   
    .Build();
0

すみません。環境がないため動作確認できていませんが、HangfireではNCronTabにより秒単位の指定ができるようです。(added support for seconds in NCronTab expressions)

6個のフォーマットで指定すれば、左端に秒を指定できるため、以下のようにすれば、解決するかもしれません。(NCronTab)

RecurringJob.AddOrUpdate(
    () => Console.WriteLine("Recurring!"),
    "*/10 * * * * *");

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。