Updated Syncer

Updated syncer to new API 0.1.5.
Change ID Comparison to string comparison, instead of EqualId()
function.
Updated RemoveAll() to use string comparison, instead of EqualId() to
remove.
Added Try Catch retry 1 after delay.  This happens when we post multiple
copies of the same DB line entry, when it doesn't exist, and is added to
the REST Server, while the REST server processes it in one thread, but
it isn't updated properly in the new thread, and it fails, cause the
item is in the database backend, and fails to process.  Solution is to
wait for a small delay, before attempting the post request again.  If it
fails a second time, then there's something majorly wrong.
This commit is contained in:
Mario Steele 2025-08-09 04:18:11 -05:00
parent 4f93a21098
commit 829aa55c9f

View file

@ -82,7 +82,7 @@ public class Syncer<T> : ISyncer where T : class, IDataModel, new()
return false;
}
if (res.AppVersion == "0.1.4")
if (res.AppVersion == "0.1.5")
{
Log.Information("Server Online! {AppVersion}", res.AppVersion);
return true;
@ -197,18 +197,34 @@ public class Syncer<T> : ISyncer where T : class, IDataModel, new()
if (entry == null) continue;
entry.MarshalData(entry.Id(), entryObject);
if (_entries.Any(x => x.EqualId(entry.Id())))
if (_entries.Any(x => x.Id() == entry.Id()))
{
var data = _entries.First(x => x.EqualId(entry.Id()));
var data = _entries.First(x => x.Id() == entry.Id());
if (data.Equals(entry)) continue;
Log.Information("Updated File Entry {EntryId} updated for {DbName}", entry.Id(), _dbName);
_entries.RemoveAll(x => x.EqualId(entry.Id()));
_entries.RemoveAll(x => x.Id() == entry.Id());
}
else
Log.Information("New File Entry {EntryId} for {DbName}", entry.Id(), _dbName);
_entries.Add(entry);
try
{
await _client.PostJsonAsync<T>(_restEndpoint, entry);
}
catch (Exception ex)
{
await Task.Delay(500);
try
{
await _client.PostJsonAsync<T>(_restEndpoint, entry);
}
catch (Exception iex)
{
Log.Error("Failed to sync entry {id} to REST Database.", entry.Id());
}
}
_lastLineCount = i;
}
}