mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-05-08 07:27:49 +08:00
Minor cleanup and formatting.
This commit is contained in:
parent
c6a87f5228
commit
3896a8f921
@ -1,7 +1,4 @@
|
|||||||
using System;
|
using Microsoft.WindowsAzure.ServiceRuntime;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using Microsoft.WindowsAzure.ServiceRuntime;
|
|
||||||
using Orchard.Environment;
|
using Orchard.Environment;
|
||||||
|
|
||||||
namespace Orchard.Azure.Services.TaskLease {
|
namespace Orchard.Azure.Services.TaskLease {
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Web;
|
|
||||||
using Orchard.Data.Conventions;
|
using Orchard.Data.Conventions;
|
||||||
|
|
||||||
namespace Orchard.TaskLease.Models
|
namespace Orchard.TaskLease.Models
|
||||||
|
@ -27,7 +27,7 @@ namespace Orchard.TaskLease.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string Acquire(string taskName, DateTime expiredUtc) {
|
public string Acquire(string taskName, DateTime expiredUtc) {
|
||||||
var machineName = _applicationEnvironment.GetEnvironmentIdentifier();
|
var environmentIdentifier = _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);
|
||||||
@ -36,7 +36,7 @@ namespace Orchard.TaskLease.Services {
|
|||||||
if (taskLease == null) {
|
if (taskLease == null) {
|
||||||
taskLease = new TaskLeaseRecord {
|
taskLease = new TaskLeaseRecord {
|
||||||
TaskName = taskName,
|
TaskName = taskName,
|
||||||
MachineName = machineName,
|
MachineName = environmentIdentifier,
|
||||||
State = String.Empty,
|
State = String.Empty,
|
||||||
UpdatedUtc = _clock.UtcNow,
|
UpdatedUtc = _clock.UtcNow,
|
||||||
ExpiredUtc = expiredUtc
|
ExpiredUtc = expiredUtc
|
||||||
@ -49,12 +49,12 @@ namespace Orchard.TaskLease.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// lease can't be aquired only if for a different machine and it has not expired
|
// lease can't be aquired only if for a different machine and it has not expired
|
||||||
if (taskLease.MachineName != machineName && taskLease.ExpiredUtc >= _clock.UtcNow) {
|
if (taskLease.MachineName != environmentIdentifier && taskLease.ExpiredUtc >= _clock.UtcNow) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise update information
|
// otherwise update information
|
||||||
taskLease.MachineName = machineName;
|
taskLease.MachineName = environmentIdentifier;
|
||||||
taskLease.UpdatedUtc = _clock.UtcNow;
|
taskLease.UpdatedUtc = _clock.UtcNow;
|
||||||
taskLease.ExpiredUtc = expiredUtc;
|
taskLease.ExpiredUtc = expiredUtc;
|
||||||
|
|
||||||
@ -64,10 +64,10 @@ namespace Orchard.TaskLease.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Update(string taskName, string state) {
|
public void Update(string taskName, string state) {
|
||||||
var machineName = _applicationEnvironment.GetEnvironmentIdentifier();
|
var environmentIdentifier = _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 == environmentIdentifier);
|
||||||
|
|
||||||
if (taskLease == null) {
|
if (taskLease == null) {
|
||||||
return;
|
return;
|
||||||
@ -78,10 +78,10 @@ namespace Orchard.TaskLease.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Update(string taskName, string state, DateTime expiredUtc) {
|
public void Update(string taskName, string state, DateTime expiredUtc) {
|
||||||
var machineName = _applicationEnvironment.GetEnvironmentIdentifier();
|
var environmentIdentifier = _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 == environmentIdentifier);
|
||||||
|
|
||||||
if (taskLease == null) {
|
if (taskLease == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -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 = _applicationEnvironment.GetEnvironmentIdentifier();
|
var environmentIdentifier = _applicationEnvironment.GetEnvironmentIdentifier();
|
||||||
var hasLockRecord = false;
|
var hasLockRecord = false;
|
||||||
|
|
||||||
ExecuteOnSeparateTransaction(repository => {
|
ExecuteOnSeparateTransaction(repository => {
|
||||||
@ -148,16 +148,16 @@ namespace Orchard.Tasks.Locking.Services {
|
|||||||
|
|
||||||
repository.Create(new DistributedLockRecord {
|
repository.Create(new DistributedLockRecord {
|
||||||
Name = internalName,
|
Name = internalName,
|
||||||
MachineName = localMachineName,
|
MachineName = environmentIdentifier,
|
||||||
CreatedUtc = _clock.UtcNow,
|
CreatedUtc = _clock.UtcNow,
|
||||||
ValidUntilUtc = maxValidFor.HasValue ? _clock.UtcNow + maxValidFor.Value : default(DateTime?)
|
ValidUntilUtc = maxValidFor.HasValue ? _clock.UtcNow + maxValidFor.Value : default(DateTime?)
|
||||||
});
|
});
|
||||||
|
|
||||||
hasLockRecord = true;
|
hasLockRecord = true;
|
||||||
}
|
}
|
||||||
else if (record.MachineName == localMachineName) {
|
else if (record.MachineName == environmentIdentifier) {
|
||||||
// Existing lock was for correct machine name => lock record exists.
|
// Existing lock was for correct machine name => lock record exists.
|
||||||
Logger.Debug("Found a valid record for lock '{0}' and current local machine name '{1}'.", internalName, localMachineName);
|
Logger.Debug("Found a valid record for lock '{0}' and current local machine name '{1}'.", internalName, environmentIdentifier);
|
||||||
hasLockRecord = true;
|
hasLockRecord = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user