We are using Hangfire with Umbraco v10 to create a recurring job that unpublishes some nodes.
We are getting the following error when the job is triggered:
System.InvalidOperationException (WN1SDWK000GBL:7100)
This SqlTransaction has completed; it is no longer usable.System.InvalidOperationException: This SqlTransaction has completed; it is no longer usable.
at Microsoft.Data.SqlClient.SqlTransaction.ZombieCheck()
at Microsoft.Data.SqlClient.SqlTransaction.get_IsolationLevel()
at Umbraco.Cms.Infrastructure.Scoping.Scope.get_Database()
at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.ContentTypeCommonRepository.GetAllTypesInternal()
at Umbraco.Extensions.AppCacheExtensions.<>c__DisplayClass0_0`1.<GetCacheItem>b__0()
at Umbraco.Cms.Core.Cache.SafeLazy.<>c__DisplayClass1_0.<GetSafeLazy>b__0()
--- End of stack trace from previous location ---
at Umbraco.Cms.Core.Cache.ObjectCacheAppCache.Get(String key, Func`1 factory, Nullable`1 timeout, Boolean isSliding, String[] dependentFiles)
at Umbraco.Cms.Core.Cache.DeepCloneAppCache.Get(String key, Func`1 factory, Nullable`1 timeout, Boolean isSliding, String[] dependentFiles)
at Umbraco.Extensions.AppCacheExtensions.GetCacheItem[T](IAppPolicyCache provider, String cacheKey, Func`1 getCacheItem, Nullable`1 timeout, Boolean isSliding, String[] dependentFiles)
at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.ContentTypeCommonRepository.GetAllTypes()
at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.ContentTypeRepository.GetAllWithFullCachePolicy()
at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.ContentTypeRepositoryBase`1.PerformGetAll(Int32[] ids)
at Umbraco.Cms.Core.Cache.FullDataSetRepositoryCachePolicy`2.GetAllCached(Func`2 performGetAll)
at Umbraco.Cms.Core.Cache.FullDataSetRepositoryCachePolicy`2.GetAll(TId[] ids, Func`2 performGetAll)
at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.ContentTypeRepository.PerformGet(String alias)
at Umbraco.Cms.Core.Services.ContentTypeServiceBase`2.Get(String alias)
at Skoleforeningenv10.Core.Features.OpenPositions.OpenPositionsService.UnpublishOpenPositions() in C:\home\site\repository\src\Skoleforeningenv10.Core\Features\OpenPositions\OpenPositionsService.cs:line 23
This is the code for the service:
public class OpenPositionsService
{
private readonly IServiceScopeFactory _serviceScopeFactory;
public OpenPositionsService(IServiceScopeFactory serviceScopeFactory)
{
_serviceScopeFactory = serviceScopeFactory;
}
public void UnpublishOpenPositions()
{
using var scope = _serviceScopeFactory.CreateScope();
var umbracoContextFactory = scope.ServiceProvider.GetService<IUmbracoContextFactory>();
umbracoContextFactory.EnsureUmbracoContext();
var contentTypeService = scope.ServiceProvider.GetService<IContentTypeService>();
var contentService = scope.ServiceProvider.GetService<IContentService>();
var openPositionType = contentTypeService.Get(OpenPosition.ModelTypeAlias);
var openPositions = contentService.GetPagedOfType(openPositionType.Id, 0, 1000, out var totalRecords, null, Ordering.By("Id", Direction.Descending))
.Where(x => x.Published == true);
foreach (var openPosition in openPositions)
{
var endDate = openPosition.GetValue<DateTime?>("endDate");
if (endDate != null && endDate < DateTime.Now)
{
contentService.Unpublish(openPosition);
}
}
}
}
This works just fine locally, but not on Umbraco cloud. What might have gone wrong?