mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Refactor renamed IMachineNameProvider.
This commit is contained in:
parent
40071a6050
commit
c6a87f5228
@ -15,7 +15,7 @@
|
|||||||
<component instance-scope="single-instance" type="Orchard.Azure.Services.Environment.Configuration.AzureBlobShellSettingsManager, Orchard.Azure" service="Orchard.Environment.Configuration.IShellSettingsManager"></component>
|
<component instance-scope="single-instance" type="Orchard.Azure.Services.Environment.Configuration.AzureBlobShellSettingsManager, Orchard.Azure" service="Orchard.Environment.Configuration.IShellSettingsManager"></component>
|
||||||
|
|
||||||
<!-- Configure Orchard to use role instance ID instead of Windows machine name for task lease records. -->
|
<!-- Configure Orchard to use role instance ID instead of Windows machine name for task lease records. -->
|
||||||
<component instance-scope="single-instance" type="Orchard.Azure.Services.TaskLease.AzureMachineNameProvider, Orchard.Azure" service="Orchard.Environment.IMachineNameProvider, Orchard.Framework"></component>
|
<component instance-scope="single-instance" type="Orchard.Azure.Services.TaskLease.ApplicationEnvironment, Orchard.Azure" service="Orchard.Environment.IApplicationEnvironment, Orchard.Framework"></component>
|
||||||
|
|
||||||
</components>
|
</components>
|
||||||
</autofac>
|
</autofac>
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
<autofac defaultAssembly="Orchard.Framework">
|
<autofac defaultAssembly="Orchard.Framework">
|
||||||
<components>
|
<components>
|
||||||
<component instance-scope="single-instance" type="Orchard.Environment.MachineNameProvider, Orchard.Framework" service="Orchard.Environment.IMachineNameProvider, Orchard.Framework"></component>
|
<component instance-scope="single-instance" type="Orchard.Environment.ApplicationEnvironment, Orchard.Framework" service="Orchard.Environment.IApplicationEnvironment, Orchard.Framework"></component>
|
||||||
<!--<component instance-scope="single-instance"
|
<!--<component instance-scope="single-instance"
|
||||||
type="Orchard.Environment.Configuration.AzureBlobTenantManager"
|
type="Orchard.Environment.Configuration.AzureBlobTenantManager"
|
||||||
service="Orchard.Environment.Configuration.IShellSettingsManager">
|
service="Orchard.Environment.Configuration.IShellSettingsManager">
|
||||||
|
@ -272,7 +272,7 @@
|
|||||||
<Compile Include="Localization\DateTimePartsTests.cs" />
|
<Compile Include="Localization\DateTimePartsTests.cs" />
|
||||||
<Compile Include="Localization\DefaultDateLocalizationServicesTests.cs" />
|
<Compile Include="Localization\DefaultDateLocalizationServicesTests.cs" />
|
||||||
<Compile Include="Localization\DefaultDateFormatterTests.cs" />
|
<Compile Include="Localization\DefaultDateFormatterTests.cs" />
|
||||||
<Compile Include="Stubs\StubMachineNameProvider.cs" />
|
<Compile Include="Stubs\StubApplicationEnvironment.cs" />
|
||||||
<Compile Include="Stubs\StubCultureSelector.cs" />
|
<Compile Include="Stubs\StubCultureSelector.cs" />
|
||||||
<Compile Include="Localization\TestHelpers.cs" />
|
<Compile Include="Localization\TestHelpers.cs" />
|
||||||
<Compile Include="Logging\OrchardFileAppenderTests.cs" />
|
<Compile Include="Logging\OrchardFileAppenderTests.cs" />
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
using Orchard.Environment;
|
using Orchard.Environment;
|
||||||
|
|
||||||
namespace Orchard.Tests.Stubs {
|
namespace Orchard.Tests.Stubs {
|
||||||
public class StubMachineNameProvider : IMachineNameProvider {
|
public class StubApplicationEnvironment : IApplicationEnvironment {
|
||||||
public StubMachineNameProvider() {
|
public StubApplicationEnvironment() {
|
||||||
MachineName = "Orchard Machine";
|
MachineName = "Orchard Machine";
|
||||||
}
|
}
|
||||||
public string MachineName { get; set; }
|
public string MachineName { get; set; }
|
||||||
public string GetMachineName() {
|
public string GetEnvironmentIdentifier() {
|
||||||
return MachineName;
|
return MachineName;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,7 +17,7 @@ namespace Orchard.Tests.Tasks {
|
|||||||
public class DistributedLockServiceTests : DatabaseEnabledTestsBase {
|
public class DistributedLockServiceTests : DatabaseEnabledTestsBase {
|
||||||
private const string LockName = "Orchard Test Lock";
|
private const string LockName = "Orchard Test Lock";
|
||||||
private DistributedLockService _distributedLockService;
|
private DistributedLockService _distributedLockService;
|
||||||
private StubMachineNameProvider _machineNameProvider;
|
private StubApplicationEnvironment _applicationEnvironment;
|
||||||
private IRepository<DistributedLockRecord> _distributedLockRepository;
|
private IRepository<DistributedLockRecord> _distributedLockRepository;
|
||||||
private ITransactionManager _transactionManager;
|
private ITransactionManager _transactionManager;
|
||||||
|
|
||||||
@ -27,14 +27,14 @@ namespace Orchard.Tests.Tasks {
|
|||||||
|
|
||||||
public override void Register(ContainerBuilder builder) {
|
public override void Register(ContainerBuilder builder) {
|
||||||
builder.RegisterType<StubClock>().As<IClock>();
|
builder.RegisterType<StubClock>().As<IClock>();
|
||||||
builder.RegisterType<StubMachineNameProvider>().As<IMachineNameProvider>().SingleInstance();
|
builder.RegisterType<StubApplicationEnvironment>().As<IApplicationEnvironment>().SingleInstance();
|
||||||
builder.RegisterType<DistributedLockService>().AsSelf();
|
builder.RegisterType<DistributedLockService>().AsSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
base.Init();
|
base.Init();
|
||||||
_distributedLockService = _container.Resolve<DistributedLockService>();
|
_distributedLockService = _container.Resolve<DistributedLockService>();
|
||||||
_machineNameProvider = (StubMachineNameProvider)_container.Resolve<IMachineNameProvider>();
|
_applicationEnvironment = (StubApplicationEnvironment)_container.Resolve<IApplicationEnvironment>();
|
||||||
_distributedLockRepository = _container.Resolve<IRepository<DistributedLockRecord>>();
|
_distributedLockRepository = _container.Resolve<IRepository<DistributedLockRecord>>();
|
||||||
_transactionManager = _container.Resolve<ITransactionManager>();
|
_transactionManager = _container.Resolve<ITransactionManager>();
|
||||||
}
|
}
|
||||||
@ -88,9 +88,9 @@ namespace Orchard.Tests.Tasks {
|
|||||||
[Test]
|
[Test]
|
||||||
public void TryAcquiringLockTwiceFails() {
|
public void TryAcquiringLockTwiceFails() {
|
||||||
IDistributedLock @lock;
|
IDistributedLock @lock;
|
||||||
_machineNameProvider.MachineName = "Orchard Test Machine 1";
|
_applicationEnvironment.MachineName = "Orchard Test Machine 1";
|
||||||
var attempt1 = _distributedLockService.TryAcquireLock(LockName, TimeSpan.FromSeconds(60), out @lock);
|
var attempt1 = _distributedLockService.TryAcquireLock(LockName, TimeSpan.FromSeconds(60), out @lock);
|
||||||
_machineNameProvider.MachineName = "Orchard Test Machine 2";
|
_applicationEnvironment.MachineName = "Orchard Test Machine 2";
|
||||||
var attempt2 = _distributedLockService.TryAcquireLock(LockName, TimeSpan.FromSeconds(60), out @lock);
|
var attempt2 = _distributedLockService.TryAcquireLock(LockName, TimeSpan.FromSeconds(60), out @lock);
|
||||||
|
|
||||||
Assert.That(attempt1, Is.True);
|
Assert.That(attempt1, Is.True);
|
||||||
@ -151,9 +151,9 @@ namespace Orchard.Tests.Tasks {
|
|||||||
[Test]
|
[Test]
|
||||||
public void MultipleAcquisitionsFromDifferentMachinesShouldFail() {
|
public void MultipleAcquisitionsFromDifferentMachinesShouldFail() {
|
||||||
IDistributedLock @lock;
|
IDistributedLock @lock;
|
||||||
_machineNameProvider.MachineName = "Orchard Test Machine 1";
|
_applicationEnvironment.MachineName = "Orchard Test Machine 1";
|
||||||
var attempt1 = _distributedLockService.TryAcquireLock(LockName, TimeSpan.FromMinutes(60), out @lock);
|
var attempt1 = _distributedLockService.TryAcquireLock(LockName, TimeSpan.FromMinutes(60), out @lock);
|
||||||
_machineNameProvider.MachineName = "Orchard Test Machine 2";
|
_applicationEnvironment.MachineName = "Orchard Test Machine 2";
|
||||||
var attempt2 = _distributedLockService.TryAcquireLock(LockName, TimeSpan.FromMinutes(60), out @lock);
|
var attempt2 = _distributedLockService.TryAcquireLock(LockName, TimeSpan.FromMinutes(60), out @lock);
|
||||||
|
|
||||||
Assert.That(attempt1, Is.True);
|
Assert.That(attempt1, Is.True);
|
||||||
@ -163,9 +163,9 @@ namespace Orchard.Tests.Tasks {
|
|||||||
[Test]
|
[Test]
|
||||||
public void MultipleAcquisitionsFromDifferentMachinesOnDifferentTenantShouldSucceed() {
|
public void MultipleAcquisitionsFromDifferentMachinesOnDifferentTenantShouldSucceed() {
|
||||||
IDistributedLock @lock;
|
IDistributedLock @lock;
|
||||||
_machineNameProvider.MachineName = "Orchard Test Machine 1";
|
_applicationEnvironment.MachineName = "Orchard Test Machine 1";
|
||||||
var attempt1 = _distributedLockService.TryAcquireLock(LockName, TimeSpan.FromSeconds(60), out @lock);
|
var attempt1 = _distributedLockService.TryAcquireLock(LockName, TimeSpan.FromSeconds(60), out @lock);
|
||||||
_machineNameProvider.MachineName = "Orchard Test Machine 2";
|
_applicationEnvironment.MachineName = "Orchard Test Machine 2";
|
||||||
_shellSettings.Name = "Foo";
|
_shellSettings.Name = "Foo";
|
||||||
var attempt2 = _distributedLockService.TryAcquireLock(LockName, TimeSpan.FromSeconds(60), out @lock);
|
var attempt2 = _distributedLockService.TryAcquireLock(LockName, TimeSpan.FromSeconds(60), out @lock);
|
||||||
|
|
||||||
@ -215,14 +215,14 @@ namespace Orchard.Tests.Tasks {
|
|||||||
IDistributedLock @lock;
|
IDistributedLock @lock;
|
||||||
|
|
||||||
// Create a never expiring lock.
|
// Create a never expiring lock.
|
||||||
_machineNameProvider.MachineName = "Orchard Test Machine 1";
|
_applicationEnvironment.MachineName = "Orchard Test Machine 1";
|
||||||
var attempt1 = _distributedLockService.TryAcquireLock(LockName, maxValidFor: null, timeout: null, dLock: out @lock);
|
var attempt1 = _distributedLockService.TryAcquireLock(LockName, maxValidFor: null, timeout: null, dLock: out @lock);
|
||||||
|
|
||||||
// Release the lock.
|
// Release the lock.
|
||||||
@lock.Dispose();
|
@lock.Dispose();
|
||||||
|
|
||||||
// Acquire the lock from another machine.
|
// Acquire the lock from another machine.
|
||||||
_machineNameProvider.MachineName = "Orchard Test Machine 2";
|
_applicationEnvironment.MachineName = "Orchard Test Machine 2";
|
||||||
var attempt2 = _distributedLockService.TryAcquireLock(LockName, maxValidFor: null, timeout: null, dLock: out @lock);
|
var attempt2 = _distributedLockService.TryAcquireLock(LockName, maxValidFor: null, timeout: null, dLock: out @lock);
|
||||||
|
|
||||||
// Validate the results.
|
// Validate the results.
|
||||||
@ -259,7 +259,7 @@ namespace Orchard.Tests.Tasks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private string GetMachineName() {
|
private string GetMachineName() {
|
||||||
return _machineNameProvider.GetMachineName();
|
return _applicationEnvironment.GetEnvironmentIdentifier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<autofac defaultAssembly="Orchard.Framework">
|
<autofac defaultAssembly="Orchard.Framework">
|
||||||
<components>
|
<components>
|
||||||
<component instance-scope="single-instance" type="Orchard.Localization.Services.CultureDateTimeFormatProvider, Orchard.Framework" service="Orchard.Localization.Services.IDateTimeFormatProvider"></component>
|
<component instance-scope="single-instance" type="Orchard.Localization.Services.CultureDateTimeFormatProvider, Orchard.Framework" service="Orchard.Localization.Services.IDateTimeFormatProvider"></component>
|
||||||
<component instance-scope="single-instance" type="Orchard.Environment.MachineNameProvider, Orchard.Framework" service="Orchard.Environment.IMachineNameProvider, Orchard.Framework"></component>
|
<component instance-scope="single-instance" type="Orchard.Environment.ApplicationEnvironment, Orchard.Framework" service="Orchard.Environment.IApplicationEnvironment, Orchard.Framework"></component>
|
||||||
</components>
|
</components>
|
||||||
</autofac>
|
</autofac>
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Services\Environment\Configuration\DefaultPlatformConfigurationAccessor.cs" />
|
<Compile Include="Services\Environment\Configuration\DefaultPlatformConfigurationAccessor.cs" />
|
||||||
<Compile Include="Services\Environment\Configuration\IPlatformConfigurationAccessor.cs" />
|
<Compile Include="Services\Environment\Configuration\IPlatformConfigurationAccessor.cs" />
|
||||||
<Compile Include="Services\TaskLease\AzureMachineNameProvider.cs" />
|
<Compile Include="Services\TaskLease\AzureApplicationEnvironment.cs" />
|
||||||
<Content Include="Web.config" />
|
<Content Include="Web.config" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Content Include="Module.txt" />
|
<Content Include="Module.txt" />
|
||||||
|
@ -5,8 +5,8 @@ using Microsoft.WindowsAzure.ServiceRuntime;
|
|||||||
using Orchard.Environment;
|
using Orchard.Environment;
|
||||||
|
|
||||||
namespace Orchard.Azure.Services.TaskLease {
|
namespace Orchard.Azure.Services.TaskLease {
|
||||||
public class AzureMachineNameProvider : IMachineNameProvider {
|
public class AzureApplicationEnvironment : IApplicationEnvironment {
|
||||||
public string GetMachineName() {
|
public string GetEnvironmentIdentifier() {
|
||||||
return RoleEnvironment.CurrentRoleInstance.Id;
|
return RoleEnvironment.CurrentRoleInstance.Id;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,20 +14,20 @@ namespace Orchard.TaskLease.Services {
|
|||||||
|
|
||||||
private readonly IRepository<TaskLeaseRecord> _repository;
|
private readonly IRepository<TaskLeaseRecord> _repository;
|
||||||
private readonly IClock _clock;
|
private readonly IClock _clock;
|
||||||
private readonly IMachineNameProvider _machineNameProvider;
|
private readonly IApplicationEnvironment _applicationEnvironment;
|
||||||
|
|
||||||
public TaskLeaseService(
|
public TaskLeaseService(
|
||||||
IRepository<TaskLeaseRecord> repository,
|
IRepository<TaskLeaseRecord> repository,
|
||||||
IClock clock,
|
IClock clock,
|
||||||
IMachineNameProvider machineNameProvider) {
|
IApplicationEnvironment applicationEnvironment) {
|
||||||
|
|
||||||
_repository = repository;
|
_repository = repository;
|
||||||
_clock = clock;
|
_clock = clock;
|
||||||
_machineNameProvider = machineNameProvider;
|
_applicationEnvironment = applicationEnvironment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Acquire(string taskName, DateTime expiredUtc) {
|
public string Acquire(string taskName, DateTime expiredUtc) {
|
||||||
var machineName = _machineNameProvider.GetMachineName();
|
var machineName = _applicationEnvironment.GetEnvironmentIdentifier();
|
||||||
|
|
||||||
// retrieve current lease for the specified task
|
// retrieve current lease for the specified task
|
||||||
var taskLease = _repository.Get(x => x.TaskName == taskName);
|
var taskLease = _repository.Get(x => x.TaskName == taskName);
|
||||||
@ -64,7 +64,7 @@ namespace Orchard.TaskLease.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Update(string taskName, string state) {
|
public void Update(string taskName, string state) {
|
||||||
var machineName = _machineNameProvider.GetMachineName();
|
var machineName = _applicationEnvironment.GetEnvironmentIdentifier();
|
||||||
|
|
||||||
// retrieve current lease for the specified task
|
// retrieve current lease for the specified task
|
||||||
var taskLease = _repository.Get(x => x.TaskName == taskName && x.MachineName == machineName);
|
var taskLease = _repository.Get(x => x.TaskName == taskName && x.MachineName == machineName);
|
||||||
@ -78,7 +78,7 @@ namespace Orchard.TaskLease.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Update(string taskName, string state, DateTime expiredUtc) {
|
public void Update(string taskName, string state, DateTime expiredUtc) {
|
||||||
var machineName = _machineNameProvider.GetMachineName();
|
var machineName = _applicationEnvironment.GetEnvironmentIdentifier();
|
||||||
|
|
||||||
// retrieve current lease for the specified task
|
// retrieve current lease for the specified task
|
||||||
var taskLease = _repository.Get(x => x.TaskName == taskName && x.MachineName == machineName);
|
var taskLease = _repository.Get(x => x.TaskName == taskName && x.MachineName == machineName);
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace Orchard.Environment {
|
namespace Orchard.Environment {
|
||||||
public class MachineNameProvider : IMachineNameProvider {
|
public class ApplicationEnvironment : IApplicationEnvironment {
|
||||||
public string GetMachineName() {
|
public string GetEnvironmentIdentifier() {
|
||||||
// Add process ID to machine name because multiple web servers can
|
// Add process ID to machine name because multiple web servers can
|
||||||
// be running on the same physical machine.
|
// be running on the same physical machine.
|
||||||
return String.Format("{0}:{1}", System.Environment.MachineName, Process.GetCurrentProcess().Id);
|
return String.Format("{0}:{1}", System.Environment.MachineName, Process.GetCurrentProcess().Id);
|
13
src/Orchard/Environment/IApplicationEnvironment.cs
Normal file
13
src/Orchard/Environment/IApplicationEnvironment.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
namespace Orchard.Environment {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Describes a service which returns the a machine identifier running the application.
|
||||||
|
/// </summary>
|
||||||
|
public interface IApplicationEnvironment {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the machine identifier running the application.
|
||||||
|
/// </summary>
|
||||||
|
string GetEnvironmentIdentifier();
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +0,0 @@
|
|||||||
namespace Orchard.Environment {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Describes a service which returns the name of the machine running the application.
|
|
||||||
/// </summary>
|
|
||||||
public interface IMachineNameProvider {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the name of the machine running the application.
|
|
||||||
/// </summary>
|
|
||||||
string GetMachineName();
|
|
||||||
}
|
|
||||||
}
|
|
@ -298,10 +298,10 @@
|
|||||||
<Compile Include="Environment\HostComponentsConfigModule.cs" />
|
<Compile Include="Environment\HostComponentsConfigModule.cs" />
|
||||||
<Compile Include="Environment\Extensions\ICriticalErrorProvider.cs" />
|
<Compile Include="Environment\Extensions\ICriticalErrorProvider.cs" />
|
||||||
<Compile Include="Environment\IFeatureEventHandler.cs" />
|
<Compile Include="Environment\IFeatureEventHandler.cs" />
|
||||||
<Compile Include="Environment\IMachineNameProvider.cs" />
|
<Compile Include="Environment\IApplicationEnvironment.cs" />
|
||||||
<Compile Include="Environment\IOrchardFrameworkAssemblies.cs" />
|
<Compile Include="Environment\IOrchardFrameworkAssemblies.cs" />
|
||||||
<Compile Include="Environment\IWorkContextEvents.cs" />
|
<Compile Include="Environment\IWorkContextEvents.cs" />
|
||||||
<Compile Include="Environment\MachineNameProvider.cs" />
|
<Compile Include="Environment\ApplicationEnvironment.cs" />
|
||||||
<Compile Include="Environment\State\ContextState.cs" />
|
<Compile Include="Environment\State\ContextState.cs" />
|
||||||
<Compile Include="Environment\ViewsBackgroundCompilation.cs" />
|
<Compile Include="Environment\ViewsBackgroundCompilation.cs" />
|
||||||
<Compile Include="Environment\Warmup\WarmupUtility.cs" />
|
<Compile Include="Environment\Warmup\WarmupUtility.cs" />
|
||||||
|
@ -17,7 +17,7 @@ namespace Orchard.Tasks.Locking.Services {
|
|||||||
|
|
||||||
public class DistributedLockService : Component, IDistributedLockService {
|
public class DistributedLockService : Component, IDistributedLockService {
|
||||||
|
|
||||||
private readonly IMachineNameProvider _machineNameProvider;
|
private readonly IApplicationEnvironment _applicationEnvironment;
|
||||||
private readonly ILifetimeScope _lifetimeScope;
|
private readonly ILifetimeScope _lifetimeScope;
|
||||||
private readonly IClock _clock;
|
private readonly IClock _clock;
|
||||||
private readonly ShellSettings _shellSettings;
|
private readonly ShellSettings _shellSettings;
|
||||||
@ -25,14 +25,14 @@ namespace Orchard.Tasks.Locking.Services {
|
|||||||
private readonly TimeSpan _defaultRepeatInterval;
|
private readonly TimeSpan _defaultRepeatInterval;
|
||||||
|
|
||||||
public DistributedLockService(
|
public DistributedLockService(
|
||||||
IMachineNameProvider machineNameProvider,
|
IApplicationEnvironment applicationEnvironment,
|
||||||
ILifetimeScope lifetimeScope,
|
ILifetimeScope lifetimeScope,
|
||||||
IClock clock,
|
IClock clock,
|
||||||
ShellSettings shellSettings) {
|
ShellSettings shellSettings) {
|
||||||
_clock = clock;
|
_clock = clock;
|
||||||
_lifetimeScope = lifetimeScope;
|
_lifetimeScope = lifetimeScope;
|
||||||
_shellSettings = shellSettings;
|
_shellSettings = shellSettings;
|
||||||
_machineNameProvider = machineNameProvider;
|
_applicationEnvironment = applicationEnvironment;
|
||||||
_locks = new Dictionary<string, DistributedLock>();
|
_locks = new Dictionary<string, DistributedLock>();
|
||||||
_defaultRepeatInterval = TimeSpan.FromMilliseconds(500);
|
_defaultRepeatInterval = TimeSpan.FromMilliseconds(500);
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ namespace Orchard.Tasks.Locking.Services {
|
|||||||
private DistributedLock AcquireLockInternal(string name, TimeSpan? maxValidFor, TimeSpan? timeout, bool throwOnTimeout) {
|
private DistributedLock AcquireLockInternal(string name, TimeSpan? maxValidFor, TimeSpan? timeout, bool throwOnTimeout) {
|
||||||
var internalName = GetInternalLockName(name);
|
var internalName = GetInternalLockName(name);
|
||||||
var monitorTimeout = timeout.HasValue ? timeout.Value : TimeSpan.FromMilliseconds(-1); // -1 ms is .NET magic number for "infinite".
|
var monitorTimeout = timeout.HasValue ? timeout.Value : TimeSpan.FromMilliseconds(-1); // -1 ms is .NET magic number for "infinite".
|
||||||
var monitorObj = String.Intern(String.Format("{0}:{1}", _machineNameProvider.GetMachineName(), internalName));
|
var monitorObj = String.Intern(String.Format("{0}:{1}", _applicationEnvironment.GetEnvironmentIdentifier(), internalName));
|
||||||
|
|
||||||
if (!Monitor.TryEnter(monitorObj, monitorTimeout)) {
|
if (!Monitor.TryEnter(monitorObj, monitorTimeout)) {
|
||||||
Logger.Debug("Could not enter local monitor for lock '{0}' within the specified timeout ({1}).", internalName, timeout);
|
Logger.Debug("Could not enter local monitor for lock '{0}' within the specified timeout ({1}).", internalName, timeout);
|
||||||
@ -136,7 +136,7 @@ namespace Orchard.Tasks.Locking.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private bool EnsureDistributedLockRecord(string internalName, TimeSpan? maxValidFor) {
|
private bool EnsureDistributedLockRecord(string internalName, TimeSpan? maxValidFor) {
|
||||||
var localMachineName = _machineNameProvider.GetMachineName();
|
var localMachineName = _applicationEnvironment.GetEnvironmentIdentifier();
|
||||||
var hasLockRecord = false;
|
var hasLockRecord = false;
|
||||||
|
|
||||||
ExecuteOnSeparateTransaction(repository => {
|
ExecuteOnSeparateTransaction(repository => {
|
||||||
|
Loading…
Reference in New Issue
Block a user