kubernetes - Hangfire:初始化对象的问题
问题描述
因此,我在 kubernetes pod 上运行了一个 API img,并将其配置为使用 Hangfire 将一些日志发送到位于同一环境中的 mssql DB。
现在每次尝试此操作时,我都会收到以下错误。
Hangfire.AutomaticRetryAttribute[0]
Failed to process the job '14537': an exception occurred. Retry attempt 4 of 10 will be performed in 00:03:32.
System.InvalidOperationException: Unable to resolve service for type 'Aftermarket.Server.Common.PqatExport.PQATRepository' while attempting to activate 'Aftermarket.Server.Common.PqatExport.PQATExportHandler'.
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
at Hangfire.Server.CoreBackgroundJobPerformer.Perform(PerformContext context)
at Hangfire.Server.BackgroundJobPerformer.<>c__DisplayClass9_0.<PerformJobWithFilters>b__0()
at Hangfire.Server.BackgroundJobPerformer.InvokePerformFilter(IServerFilter filter, PerformingContext preContext, Func`1 continuation)
at Hangfire.Server.BackgroundJobPerformer.PerformJobWithFilters(PerformContext context, IEnumerable`1 filters)
at Hangfire.Server.BackgroundJobPerformer.Perform(PerformContext context)
at Hangfire.Server.Worker.PerformJob(BackgroundProcessContext context, IStorageConnection connection, String jobId)
现在这里的另一个问题是,它试图在 PQATRepository 和 PQATExportHandler 的帮助下运行传输,这些甚至不是该 API 应该用于传输的类属于其他 API(位于同一环境或同一 pod 中,所以说)。
这个 api 应该使用 HwsPQATRepository 和 HwsPQATExportHandler。然而,所有 PQATExport 类都位于两个 API 都可以访问的共享项目中:
这是我的 startup.cs 的相关部分
services.AddHangfire(configuration => configuration
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseSqlServerStorage(hangFireConnectionString,
new SqlServerStorageOptions
{
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
QueuePollInterval = TimeSpan.Zero,
UseRecommendedIsolationLevel = true,
UsePageLocksOnDequeue = true,
DisableGlobalLocks = true,
}));
// Add the processing server as IHostedService
services.AddHangfireServer();
// Add own stuff
//services.AddSingleton<ReportGenerator>();
services.AddScoped<HwsPQATRepository>();
services.AddScoped<HwsPQATExportHandler>();
如果有人知道为什么 Hangfire 不断崩溃,那将有很大帮助。亲切的问候
解决方案
推荐阅读
- python - 如果它是python数据框中的字母,则从字符串中删除最后一个字符
- macos - 为什么 c++ SFML 库不适用于 macOS-arm64?
- javascript - 如何修复第二次选择时的延迟显示数据
- matlab - 显式 FD 格式的周期性边界条件
- javascript - 使用 Laravel 应用程序中的 Google 表格打开 Excel 文档
- javascript - 在 React Native Expo App 的 config.js 文件中检索 Firebase 数据
- python - 有什么更好的办法?导入模块是导入模块还是导入 2 个模块?
- python - 如何将来自 opencv 的输出视频存储到 Dash 的 dcc.store 组件中(Plotly)
- android - 从文件中读取 Fastfile 的密码 - Android
- pdf - 使用 poppler 生成的 XML 中的坐标来构建电子邮件模板