How To
How to purge the Hangfire job queue
4 min
when large numbers (perhaps thousands) of relatively low value jobs are enqueued within hangfire, and only a few are processing slowly at any one time (which can happen for a variety of reasons), it may be necessary to purge the job queue in order for newer jobs of higher value to process in a typical rapid way follow the instructions below to purge the queue swimlane platform installer (standalone and ha) embedded \<namespace> is default existing \<namespace> depends on environment kubectl scale deployment swimlane tasks replicas=0 n default kubectl scale deployment swimlane api replicas=0 n default follow the instructions in mongodb accessing the mongo shell and other cli tools with ssl to open a command line query interface for mongodb check the current indexes first before dropping the collections run this query again after dropping the collections to ensure all of the indexes were recreated note the numbers of indexes depend on the swimlane 10 x version used db getcollectionnames() foreach(function(collection) { if (collection indexof("hangfire") > 1){ indexes = db\[collection] getindexes(); print("indexes for " + collection + " "); print(indexes length); indexes foreach(function(item){ print(item name); }); } }); note the number of recurring jobs in the hangfire dashboard before dropping hangfire collections after dropping the hangfire collections, confirm the recurring jobs count is the same if it isn't, restart the tasks pods again to re initialize the recurring jobs issue the following commands to drop all hangfire collections in mongodb use swimlane; db getcollectionnames() foreach(function(collname){ if(collname includes('hangfire')){ print('delete collection ' + collname); db getcollection(collname) drop() } }); start swimlane’s task service again using standalone kubectl scale deployment swimlane tasks replicas=1 kubectl scale deployment swimlane api replicas=1 ha kubectl scale deployment swimlane tasks replicas=3 kubectl scale deployment swimlane api replicas=3 confirm that the several hangfire queues' numbers are accurate