You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Hangfire中AutomaticRetryAttribute过滤器的配置位置咨询

Hangfire AutomaticRetryAttribute: Where to Configure It?

Great question! Let's break this down clearly:

You must configure this global retry filter in the client application that enqueues jobs — this is the critical piece. Here's why:

When Hangfire adds a job to the queue, it serializes the global filter settings (like your Attempts = 3) into the job's metadata. The server processing the job will read this metadata when executing the task, meaning the retry behavior is locked in at the moment the job is enqueued, not when it runs.

In short: If you set the global filter on the client, every job sent from that client will have the 3-retry rule baked in, no matter what configuration the processing server uses.

That said, it's also a smart practice to add the same configuration to your job-processing server as a fallback. This covers edge cases where jobs might be enqueued from other clients that don't have the retry filter set up — the server's global filter will provide a default retry policy for those tasks.

A couple of extra notes to round this out:

  • If you need per-job retry overrides, just decorate the specific job method with [AutomaticRetry(Attempts = 5)] (or whatever number you need) — this takes priority over the global filter.
  • The code snippet you're using works perfectly for both client and server:
    GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 3 });
    
    Place this in your client's startup logic (like Program.cs in an ASP.NET Core app) and your server's startup code.

内容的提问来源于stack exchange,提问作者D.R.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:34:25