【问题标题】:HangFire migration from serviceHangFire 从服务迁移
【发布时间】:2021-10-16 23:50:23
【问题描述】:

在我的应用程序中(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();

来自 ConfigureServices(启动)

        // 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;
        });

【问题讨论】:

标签: c# .net hangfire hangfire-sql


【解决方案1】:

我终于有时间分享我的发现。这完全是由于 SQL Server 端的特权。很多工作要弄清楚如何设置登录名并分配所需的权限,而不是太多:-)。如果有人遇到类似情况,请在此处发表评论,我很乐意分享我的发现。

【讨论】:

    猜你喜欢
    • 2016-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-16
    • 1970-01-01
    • 2014-04-30
    • 1970-01-01
    • 2020-09-30
    相关资源
    最近更新 更多