hangfire recurring job on every server

后端 未结 1 1491
旧巷少年郎
旧巷少年郎 2021-01-06 08:29

I have a situation where I need a recurring job registered with hangfire to run on every server in the cluster.

(The job is to copy some files locally so needs to ru

相关标签:
1条回答
  • 2021-01-06 08:56

    Found an answer using this link.

    Simply assign the job to a queue that is specific to the server you want it processing on.

    So I changed my enqueue to:

    RecurringJob.AddOrUpdate(Environment.MachineName, 
      () => CopyFiles(Environment.MachineName),
      Cron.MinuteInterval(_delay), 
      queue: Environment.MachineName.ToLower(CultureInfo.CurrentCulture));
    

    And when I start my server I do this:

    _backgroundJobServer = new BackgroundJobServer(new BackgroundJobServerOptions 
                               {
                                   Queues = new[] { Environment.MachineName.ToLower() } 
                               });
    
    0 讨论(0)
提交回复
热议问题