/* * public static long HandleItSystems() * { * ItSystemService service = new ItSystemService(); * ItSystemDao dao = new ItSystemDao(); * long count = 0; * * ItSystemRegistrationExtended itSystem = null; * while ((itSystem = dao.GetOldestEntry()) != null) * { * try * { * if (itSystem.Operation.Equals(OperationType.DELETE)) * { * service.Delete(itSystem.Uuid, itSystem.Timestamp); * } * else * { * service.Update(itSystem); * } * * count++; * * dao.Delete(itSystem.Uuid); * } * catch (TemporaryFailureException ex) * { * log.Error("Could not handle ItSystem '" + itSystem.Uuid + "' at the moment, will try later", ex); * break; * } * catch (Exception ex) * { * log.Error("Could not handle ItSystem '" + itSystem.Uuid + "'", ex); * dao.Delete(itSystem.Uuid); * } * } * * return count; * } */ public static void HandleOUs(out long count) { OrgUnitService service = new OrgUnitService(); OrgUnitDao dao = new OrgUnitDao(); count = 0; OrgUnitRegistrationExtended ou = null; while ((ou = dao.GetOldestEntry()) != null) { try { if (ou.Operation.Equals(OperationType.DELETE)) { service.Delete(ou.Uuid, ou.Timestamp); } else { service.Update(ou); } count++; dao.Delete(ou.Id); errorCount = 0; } catch (TemporaryFailureException ex) { log.Error("Could not handle ou '" + ou.Uuid + "' at the moment, will try later"); throw ex; } catch (Exception ex) { log.Error("Could not handle ou '" + ou.Uuid + "'", ex); dao.Delete(ou.Id); } } }
private static int HandleOU(OrgUnitRegistrationExtended ou, OrgUnitService service, OrgUnitDao dao) { try { OrganisationRegistryProperties.SetCurrentMunicipality(ou.Cvr); if (ou.Operation.Equals(OperationType.DELETE)) { service.Delete(ou.Uuid, ou.Timestamp); } else { service.Update(ou); } dao.OnSuccess(ou.Id); dao.Delete(ou.Id); return(0); } catch (TemporaryFailureException ex) { log.Warn("Could not handle ou '" + ou.Uuid + "' at the moment, will try later", ex); return(-1); } catch (Exception ex) { log.Error("Could not handle ou '" + ou.Uuid + "'", ex); dao.OnFailure(ou.Id, ex.Message); dao.Delete(ou.Id); return(-2); } }
public static void HandleOUs(out long count) { OrgUnitService service = new OrgUnitService(); OrgUnitDao dao = new OrgUnitDao(); count = 0; var orgUnits = dao.Get4OldestEntries(); do { if (orgUnits.Count > 0) { int subCounter = 0; Parallel.ForEach(orgUnits, (orgUnit) => { using (var cancelTokenSource = new CancellationTokenSource()) { var cancelToken = cancelTokenSource.Token; var task = Task.Run(() => HandleOU(orgUnit, service, dao), cancelToken); if (task.Wait(TimeSpan.FromSeconds(300))) { int result = task.Result; switch (result) { case -1: // we are not increment subcounter here, as this is a temporary failure, and we should sleep break; case -2: // bad data, it was logged and then throw away, nothing to see here, move along lock (orgUnits) { subCounter++; } break; default: lock (orgUnits) { subCounter++; } errorCount = 0; break; } } else { log.Warn("Timeout happended while waiting for synchronization of OrgUnit: " + orgUnit.Uuid); cancelTokenSource.Cancel(); } } }); count += subCounter; if (subCounter != orgUnits.Count) { throw new TemporaryFailureException(); } orgUnits = dao.Get4OldestEntries(); } } while (orgUnits.Count > 0); }