Skip to content

Commit

Permalink
Use singleton rather than hosted service for cleanup (#39327)
Browse files Browse the repository at this point in the history
* Use singleton rather than hosted service for cleanup

* prepare for release

* add date
  • Loading branch information
JoshLove-msft authored Oct 17, 2023
1 parent c54665c commit 2b76d84
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Release History

## 5.14.0-beta.1 (Unreleased)

### Features Added

### Breaking Changes
## 5.13.1 (2023-10-17)

### Bugs Fixed

- Fixed the disposal pattern for cached Service Bus clients so that they are disposed only on
host shutdown.

### Other Changes

- Updated the proto service definition to use bytes for application properties.

## 5.13.0 (2023-10-11)

### Features Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public ServiceBusExtensionConfigProvider(
IConverterManager converterManager,
ServiceBusClientFactory clientFactory,
ConcurrencyManager concurrencyManager,
IDrainModeManager drainModeManager)
IDrainModeManager drainModeManager,
CleanupService cleanupService)
{
_options = options.Value;
_messagingProvider = messagingProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static IWebJobsBuilder AddServiceBus(this IWebJobsBuilder builder, Action

builder.Services.AddAzureClientsCore();
builder.Services.TryAddSingleton<MessagingProvider>();
builder.Services.AddHostedService<CleanupService>();
builder.Services.AddSingleton<CleanupService>();
builder.Services.AddSingleton<ServiceBusClientFactory>();
#if NET6_0_OR_GREATER
builder.Services.AddSingleton<SettlementService>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<Description>Microsoft Azure WebJobs SDK ServiceBus Extension</Description>
<Version>5.14.0-beta.1</Version>
<Version>5.13.1</Version>
<!--The ApiCompatVersion is managed automatically and should not generally be modified manually.-->
<!--Since we are adding a new target for net6.0, we need to temporarily condition on netstandard-->
<ApiCompatVersion>5.13.0</ApiCompatVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;

namespace Microsoft.Azure.WebJobs.ServiceBus
{
internal class CleanupService : IHostedService
internal class CleanupService : IAsyncDisposable
{
private readonly MessagingProvider _provider;

Expand All @@ -16,12 +17,7 @@ public CleanupService(MessagingProvider provider)
_provider = provider;
}

public Task StartAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

public async Task StopAsync(CancellationToken cancellationToken)
public async ValueTask DisposeAsync()
{
await _provider.DisposeAsync().ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,8 @@ public async Task TestBatch_DataContractPoco()
public async Task BindToPoco()
{
var host = BuildHost<ServiceBusArgumentBindingJob>();
var provider = host.Services.GetService<MessagingProvider>();

using (host)
{
await WriteQueueMessage("{ Name: 'foo', Value: 'bar' }");
Expand All @@ -630,6 +632,10 @@ public async Task BindToPoco()
Assert.Contains("PocoValues(foo,bar)", logs);
await host.StopAsync();
}
Assert.AreEqual(0, provider.ClientCache.Count);
Assert.AreEqual(0, provider.MessageReceiverCache.Count);
Assert.AreEqual(0, provider.MessageSenderCache.Count);
Assert.AreEqual(0, provider.ActionsCache.Count);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,6 @@ public async Task StopAsync(CancellationToken cancellationToken)

QueueRuntimeProperties properties = await client.GetQueueRuntimePropertiesAsync(FirstQueueScope.QueueName, CancellationToken.None);
Assert.AreEqual(ExpectedRemainingMessages, properties.ActiveMessageCount);

var provider = _host.Services.GetService<MessagingProvider>();
Assert.AreEqual(0, provider.ClientCache.Count);
Assert.AreEqual(0, provider.MessageReceiverCache.Count);
Assert.AreEqual(0, provider.MessageSenderCache.Count);
Assert.AreEqual(0, provider.ActionsCache.Count);
}

private static bool IsError(LogMessage logMessage)
Expand Down

0 comments on commit 2b76d84

Please sign in to comment.