新创建的一个项目,为了测试。
vs2019, docker安装最新版本的mongodb, 数据库连接信息正确,没有问题。
public void ConfigureServices ( IServiceCollection services )
{
services.AddHangfire( configura =>
{
var mongoUrlBuilder = new MongoUrlBuilder( "mongodb://xxx:xxx@xxxxx/hangfire?authSource=hangfire" );
var mongoClient = new MongoClient( mongoUrlBuilder.ToMongoUrl() );
//指定存储介质
configura
.SetDataCompatibilityLevel( CompatibilityLevel.Version_170 )
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseMongoStorage( mongoClient, mongoUrlBuilder.DatabaseName, new MongoStorageOptions()
{
MigrationOptions = new MongoMigrationOptions
{
MigrationStrategy = new MigrateMongoMigrationStrategy(),
BackupStrategy = new CollectionMongoBackupStrategy()
},
Prefix = "hangfire",
CheckConnection = true
} ) ;
configura.UseConsole();
} );
services.AddHangfireServer( serverOptions =>
{
serverOptions.ServerName = "Hangfire.Mongo server 1";
} );
}
public void Configure ( IApplicationBuilder app, IWebHostEnvironment env )
{
...
app.UseHangfireDashboard();
...
}
引发的异常报错,且数据库中,没有生成对应的集合。
:“System.InvalidOperationException”(位于 Hangfire.Mongo.dll 中)
“System.InvalidOperationException”类型的异常在 Hangfire.Mongo.dll 中发生,但未在用户代码中进行处理
Could not complete migration. Never acquired lock within allowed time: 00:01:00
Either another server did not complete the migration or migration was abruptly interrupted
If migration has been interrupted you need to manually delete 'hangfire.migrationLock' and start again.