受搜索和分組缺乏的啟發,hangfire.tags提供了一種搜索和分組不同作業的方法。
在.net Core的啟動.cs:
public void ConfigureServices ( IServiceCollection services )
{
services . AddHangfire ( config =>
{
config . UseSqlServerStorage ( " connectionSting " ) ;
// config.UseTagsWithPostgreSql();
// config.UseTagsWithMySql();
// config.UseTagsWithRedis();
config . UseTagsWithSql ( ) ;
} ) ;
}否則,
GlobalConfiguration . Configuration
. UseSqlServerStorage ( " connectionSting " )
//.UseTagsWithPostgreSql()
//.UseTagsWithMySql()
//.UseTagsWithRedis();
. UseTagsWithSql ( ) ;注意:如果您的儀表板和服務器單獨運行,則需要在兩者上調用UseTags() , UseTagsWithSql() , UseTagsWithPostgreSql() , UseTagsWithMySql()或usetagswithmysql()或UseTagsWithRedis() 。
如果您的數據庫中有自定義的掛斷模式,則需要將SQL選項傳遞給存儲方法。例如:
var tagsOptions = new TagsOptions ( ) { TagsListStyle = TagsListStyle . Dropdown } ;
var hangfireSqlOptions = new SqlServerStorageOptions
{
SchemaName = " MyCustomHangFireSchema " ,
} ;
services . AddHangfire ( hangfireConfig => hangfireConfig
. SetDataCompatibilityLevel ( CompatibilityLevel . Version_180 )
. UseColouredConsoleLogProvider ( )
. UseSimpleAssemblyNameTypeSerializer ( )
. UseRecommendedSerializerSettings ( )
. UseSqlServerStorage ( " dbConnection " , hangfireSqlOptions )
. UseTagsWithSql ( tagsOptions , hangfireSqlOptions )
) ;像往常一樣,您可以為UseTags()方法提供其他選項。
這是您可以配置的:
注意:最初添加hangfire.tag(或更改上面的選項)後,您可能需要清除瀏覽器緩存,因為瀏覽器可以緩存生成的CSS/JS。
為了正確清理過期的作業標籤,默認存儲提供商需要擴展名。目前,有三個提供商:對於SQL Server,用於PostgreSQL和MySQL。
hangfire.tags提供了PerformContext對象的擴展方法,因此您需要將其添加為作業參數。
注意:像IJobCancellationToken一樣, PerformContext是一種特殊的參數類型,hangfire將自動替代。在找到工作時,您應該通過null 。
現在您可以添加一個標籤:
public void TaskMethod ( PerformContext context )
{
context . AddTags ( " Hello, world! " ) ;
}這導致標籤Hello-world。
您還可以使用屬性,在類上或方法(或兩者!)添加標籤。
[ Tag ( " TaskMethod " ) ]
public void TaskMethod ( PerformContext context )
{
....
} 在儀表板中,單擊作業時,您會看到一個新的菜單項,稱為標籤。默認情況下,此頁面將顯示系統中所有定義的標籤。單擊標籤將顯示所有作業的列表,並附上該標籤。
顯示標籤的默認視圖是所謂的TagCloud。如果您喜歡自動完成的下拉列表,則可以使用選項指定:
var options = new TagsOptions ( )
{
TagsListStyle = TagsListStyle . Dropdown
} ;
config . UseTagsWithSql ( options ) ;結果看起來像這樣:
版權(c)2018 2face-it bv
特此免費獲得許可,免費授予任何獲得此軟件副本和相關文檔文件(“軟件”)的人,以無限制地處理軟件,包括無限制的使用權,複製,複製,修改,合併,發布,分發,分發,分發,分配,sublicense和/或允許軟件允許與以下條件相關的軟件,以下是以下條件。
上述版權通知和此許可通知應包含在軟件的所有副本或大量部分中。
該軟件是“原樣”提供的,沒有任何形式的明示或暗示保證,包括但不限於適銷性,特定目的的適用性和非侵權的保證。在任何情況下,作者或版權持有人都不應對任何索賠,損害賠償或其他責任責任,無論是在合同,侵權的訴訟中還是其他責任,是由軟件,使用或與軟件中的使用或其他交易有關的。