/// <summary> /// Action: OnCreating /// Description: It is used to check the current connector sync is already going or not. /// If not then allow to proceed else cancel the schedule. This is the entry filter for all sync task. /// Sync status 1 means pending/ongoing /// </summary> /// <param name="context"></param> void IClientFilter.OnCreating(CreatingContext context) { Console.WriteLine(string.Format("Creating a job based on method `{0}`", context.Job.Method.Name)); var ccid = context.Job.Args.ElementAt(2) as string; int connectorId = (int)context.Job.Args.ElementAt(1); if (!string.IsNullOrEmpty(ccid) && connectorId > 0) { //Check connector status. If it is 1 then cancel the new schedule if (SyncRepository.GetSyncStatus(ccid: ccid, connectorId: connectorId) == 1) { context.Canceled = true; } } }
/// <summary> /// Action: OnPerforming /// Description: It is the third filter to cancel any jobs if sync status is not 1 while they are performing. /// </summary> /// <param name="context"></param> void IServerFilter.OnPerforming(PerformingContext context) { Console.WriteLine(string.Format("Job `{0}` has been performing", context.BackgroundJob?.Id)); if (context.Canceled == false) { 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) { //Check connector status. If it is not 1 then cancel it if (SyncRepository.GetSyncStatus(ccid: ccid, connectorId: connectorId) != 1) { context.Canceled = true; } } } }