HangFire从服务迁移



在我的应用程序(c# api dotnet 5修改运行为windows服务),我使用HangFire。当从Visual Studio在调试模式下运行我的应用程序时,一切工作正常,当我调用迁移时,我的数据库正在创建,包括HangFire表。

当我打包并尝试将其作为服务安装时,数据库被创建,但没有HangFire表。我已经试过了我能想到的所有方法,但就是没有运气。

有人知道从windows服务内部迁移HangFire的要求吗?

从主要

var host = Host.CreateDefaultBuilder().UseWindowsService()
.ConfigureWebHostDefaults(config =>
{
config.UseKestrel(options =>
options.Listen(IPAddress.Any, int.Parse(Configuration["port"]),
listenOptions =>
{
listenOptions.UseHttps("generated.pfx", "xxxxx");
})).UseContentRoot(pathToContentRoot);
config.UseIISIntegration();
config.UseStartup<Startup>();
})
.ConfigureAppConfiguration((buildercontext, config) =>
{
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
})
.Configure(new TMConfiguration
{
EnableLogging = true,
EnableTracing = true,
UseAutoMapper = false,
UseHealthCheck = true,
EnableSwagger = false,
ProductName = "TM Backend Server"
})
.Build();

From ConfigureServices (startup)

// running migrate and applying all migrations
context.Database.Migrate();
//adding support for Hangfire in the Db
services.AddHangfire(configuration => configuration
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseSqlServerStorage(Configuration.GetConnectionString("DbConnection"), new SqlServerStorageOptions
{
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
QueuePollInterval = TimeSpan.Zero,
PrepareSchemaIfNecessary = true,
EnableHeavyMigrations = true,
UseRecommendedIsolationLevel = true,
DisableGlobalLocks = true
})
);
services.AddHangfireServer(action =>
{
action.ServerName = $"{Environment.MachineName}:default";
action.Queues = new[] { "default" };
action.WorkerCount = Environment.ProcessorCount * 5;
});
services.AddHangfireServer(action =>
{
action.ServerName = $"{Environment.MachineName}:serial";
action.Queues = new[] { "serial" };
action.WorkerCount = 1;
});

我终于抽出时间来分享我的发现。这都是由于SQL Server端的特权。要弄清楚如何设置登录并分配所需的特权需要做很多工作,而且工作量不大:-)。如果有人遇到类似的情况,请在这里发表评论,我很乐意分享我的发现。

相关内容

  • 没有找到相关文章

最新更新