Fixed sweeplock bugs in media services background tasks.

This commit is contained in:
Sipke Schoorstra
2014-03-24 23:29:43 +01:00
parent 34d6e5198a
commit 8bda4bc6cc
2 changed files with 13 additions and 16 deletions

View File

@@ -10,8 +10,6 @@ using Orchard.Azure.MediaServices.Models.Assets;
using Orchard.Azure.MediaServices.Models.Records;
using Orchard.Azure.MediaServices.Services.TempFiles;
using Orchard.Azure.MediaServices.Services.Wams;
using Microsoft.WindowsAzure.MediaServices.Client;
using Orchard;
using Orchard.ContentManagement;
using Orchard.Data;
using Orchard.Logging;
@@ -55,14 +53,13 @@ namespace Orchard.Azure.MediaServices.Services.Assets {
void IBackgroundTask.Sweep() {
if (Monitor.TryEnter(_sweepLock)) {
Logger.Debug("Beginning sweep.");
if (!_orchardServices.WorkContext.CurrentSite.As<CloudMediaSettingsPart>().IsValid()) {
Logger.Debug("Settings are invalid; going back to sleep.");
return;
}
try {
Logger.Debug("Beginning sweep.");
if (!_orchardServices.WorkContext.CurrentSite.As<CloudMediaSettingsPart>().IsValid()) {
Logger.Debug("Settings are invalid; going back to sleep.");
return;
}
var pendingAssetsQuery =
from asset in _assetManager.LoadPendingAssets()
where _fileManager.FileExists(asset.LocalTempFileName)

View File

@@ -47,14 +47,14 @@ namespace Orchard.Azure.MediaServices.Services.Jobs {
public void Sweep() {
if (Monitor.TryEnter(_sweepLock)) {
Logger.Debug("Beginning sweep.");
if (!_orchardServices.WorkContext.CurrentSite.As<CloudMediaSettingsPart>().IsValid()) {
Logger.Debug("Settings are invalid; going back to sleep.");
return;
}
try {
Logger.Debug("Beginning sweep.");
if (!_orchardServices.WorkContext.CurrentSite.As<CloudMediaSettingsPart>().IsValid()) {
Logger.Debug("Settings are invalid; going back to sleep.");
return;
}
// Only allow this task to run on one farm node at a time.
if (_taskLeaseService.Acquire(GetType().FullName, _clock.UtcNow.AddHours(1)) != null) {
var jobs = _jobManager.GetActiveJobs().ToDictionary(job => job.WamsJobId);