/// <summary> /// Action: OnPerformed /// Description: It is the final filter to used for updating sync status to 2. /// Sync status 2 means completed. /// </summary> /// <param name="context"></param> void IServerFilter.OnPerformed(PerformedContext context) { if (context.Canceled == false && context.Exception == null) { Console.WriteLine(string.Format("Job `{0}` has been performed", context.BackgroundJob?.Id)); var ccid = context.BackgroundJob.Job.Args.ElementAt(2) as string; int connectorId = (int)context.BackgroundJob.Job.Args.ElementAt(1); if (!string.IsNullOrEmpty(ccid) && connectorId > 0) { if (GC.GetTotalMemory(false) >= 67108864) { Console.WriteLine($"GC.Generation: 2, max allocated memory: {GC.GetTotalMemory(false)}"); GC.Collect(2); GC.WaitForPendingFinalizers(); GC.Collect(2); Console.WriteLine($"Max allocated memory after GC.Collect: {GC.GetTotalMemory(false)}"); } if (GC.GetTotalMemory(false) >= 33554432) { Console.WriteLine($"GC.Generation: 1, max allocated memory: {GC.GetTotalMemory(false)}"); GC.Collect(1); GC.WaitForPendingFinalizers(); GC.Collect(1); Console.WriteLine($"Max allocated memory after GC.Collect: {GC.GetTotalMemory(false)}"); } if (GC.GetTotalMemory(false) >= 20971520) { Console.WriteLine($"GC.Generation: 0, max allocated memory: {GC.GetTotalMemory(false)}"); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); Console.WriteLine($"Max allocated memory after GC.Collect: {GC.GetTotalMemory(false)}"); } //set sync status to completed{2} var connectorLogs = new ConnectorLogs() { sync_ended_at = DateTime.UtcNow, sync_logs = new List <string>() }; SyncRepository.UpdateSyncInfo(id: connectorId, ccid: ccid, status: 2, connectorLogs: connectorLogs); } } }
/// <summary> /// Action: OnCreated /// Description: It is the second filter to update the sync status to 1 for all jobs validated by previous filter. But jobs are not to be started yet. /// Sync status 1 means pending/ongoing. /// </summary> /// <param name="context"></param> void IClientFilter.OnCreated(CreatedContext context) { if (context.Canceled == false || context.Exception == null) { Console.WriteLine(string.Format("Job is based on method `{0}` has been created with id `{1}`", context.Job.Method.Name, context.BackgroundJob?.Id)); var ccid = context.Job.Args.ElementAt(2) as string; int connectorId = (int)context.Job.Args.ElementAt(1); string jobId = context.BackgroundJob?.Id; if (!string.IsNullOrEmpty(ccid) && connectorId > 0) { //set sync status to progress{1}. var connectorLogs = new ConnectorLogs() { sync_started_at = DateTime.UtcNow, sync_ended_at = null, sync_logs = new List <string>() }; SyncRepository.UpdateSyncInfo(id: connectorId, ccid: ccid, status: 1, count: 0, jobid: jobId, connectorLogs: connectorLogs, totaluniquecount: 0, sync_updated_count: 0, deduped_count: 0, total_records_count: 0); } } }