From bdf56799cd6c4c42ec7a8dc36f56ddd17a5feeab Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Tue, 17 Dec 2019 00:02:49 +0200 Subject: Added SOURCE to JOB. Added IS_SYNCHRONIZED to TANGO_UPDATE. Added OfflineUpdates to Synchronization. Added TangoUpdates on PPC side. --- .../DefaultMachineDataSynchronizer.cs | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Synchronization/DefaultMachineDataSynchronizer.cs') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Synchronization/DefaultMachineDataSynchronizer.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Synchronization/DefaultMachineDataSynchronizer.cs index 8260eb4b3..22c3dbe20 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Synchronization/DefaultMachineDataSynchronizer.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Synchronization/DefaultMachineDataSynchronizer.cs @@ -40,6 +40,7 @@ namespace Tango.PPC.Common.Synchronization public int MaxJobs { get; set; } public int MaxJobRuns { get; set; } public int MaxMachinesEvents { get; set; } + public int MaxOfflineUpdates { get; set; } private SynchronizationStatus _currentStatus; public SynchronizationStatus CurrentStatus @@ -80,6 +81,7 @@ namespace Tango.PPC.Common.Synchronization MaxJobs = 10; MaxJobRuns = 100; MaxMachinesEvents = 100; + MaxOfflineUpdates = 50; var settings = SettingsManager.Default.GetOrCreate(); Interval = settings.SynchronizationInterval; @@ -190,6 +192,21 @@ namespace Tango.PPC.Common.Synchronization request.MachineEvents.Add(dto); } } + + if (syncDiagnostics) + { + LogManager.Log("Checking Offline Updates..."); + + var tangoUpdates = await db.TangoUpdates.Where(x => !x.IsSynchronized && (x.Status == (int)TangoUpdateStatuses.OfflineUpdateCompleted || x.Status == (int)TangoUpdateStatuses.OfflineUpdateFailed)).Take(MaxOfflineUpdates).OrderByDescending(x => x.LastUpdated).ToListAsync(); + List dtos = new List(); + + foreach (var tangoUpdate in tangoUpdates) + { + tangoUpdate.IsSynchronized = true; + var dto = TangoUpdateDTO.FromObservable(tangoUpdate); + request.OfflineUpdates.Add(dto); + } + } } return request; @@ -247,6 +264,22 @@ namespace Tango.PPC.Common.Synchronization } } + //Finalize tango updates + foreach (var tangoUpdate in request.OfflineUpdates) + { + var failedTangoUpdate = response.FailedOfflineUpdates.SingleOrDefault(x => x.Guid == tangoUpdate.Guid); + + if (failedTangoUpdate == null) + { + var dbTangoUpdate = await db.TangoUpdates.SingleOrDefaultAsync(x => x.Guid == tangoUpdate.Guid); + dbTangoUpdate.IsSynchronized = true; + } + else + { + LogManager.Log($"Synchronization Error - TangoUpdate '{tangoUpdate.ID}' cannot be stored on the server due to the following reason:\n{failedTangoUpdate.Reason}", LogCategory.Error); + } + } + await db.SaveChangesAsync(); } } -- cgit v1.3.1