Quantcast
Channel: User Simon_Weaver - Stack Overflow
Viewing all articles
Browse latest Browse all 116

Answer by Simon_Weaver for In HangFire, can I Enqueue with a queue name instead of using the Queue attribute?

$
0
0

Since adding an extra parameter seems to be so hard for the Hangfire team ;-)....

...I've found the most convenient way is to make two methods that just call the actual implementation, and put different [Queue] attributes on each.

Usually if I need to switch queues it's between dev / production and I want to just call something like RunOrder(...) with isTestOrder=boolean and not be concerned about queues at that level.

public void RunOrder(int orderId, bool isTestOrder) {   if (isTestOrder)    {      BackgroundJob.Enqueue(() => _RunTestOrder(orderId));   }    else    {      BackgroundJob.Enqueue(() => _RunOrder(orderId));   }}[Queue("dev")]public void _RunTestOrder(int orderId) {  OrderProcessor.RunOrder(orderId); // actual code to call processor}[Queue("production")]`public void _RunProductionOrder(int orderId) {  OrderProcessor.RunOrder(orderId); // is the same in both 'hangfire proxies'}

Note usage of _ to indicate these aren't meant to be called directly. I don't remember off hand if hangfire methods need to be public or not - but if they do need to be then the _ is more important.


Viewing all articles
Browse latest Browse all 116

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>