mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 15:26:30 +00:00
fixed bugs with queue handling. At least most of them
This commit is contained in:
@@ -59,7 +59,8 @@ public enum AnnotationStatus
|
||||
{
|
||||
None = 0,
|
||||
Created = 10,
|
||||
Validated = 20,
|
||||
ValidatedEdited = 25,
|
||||
Deleted = 30
|
||||
ValidatedEdited = 20,
|
||||
|
||||
Validated = 30,
|
||||
Deleted = 40
|
||||
}
|
||||
@@ -2,7 +2,8 @@ namespace Azaion.Common.Database;
|
||||
|
||||
public class AnnotationQueueRecord
|
||||
{
|
||||
public DateTime DateTime { get; set; }
|
||||
public AnnotationStatus Operation { get; set; }
|
||||
public Guid Id { get; set; }
|
||||
public DateTime DateTime { get; set; }
|
||||
public AnnotationStatus Operation { get; set; }
|
||||
public List<string> AnnotationNames { get; set; } = null!;
|
||||
}
|
||||
@@ -9,5 +9,4 @@ public class AnnotationsDb(DataOptions dataOptions) : DataConnection(dataOptions
|
||||
public ITable<Annotation> Annotations => this.GetTable<Annotation>();
|
||||
public ITable<AnnotationQueueRecord> AnnotationsQueueRecords => this.GetTable<AnnotationQueueRecord>();
|
||||
public ITable<Detection> Detections => this.GetTable<Detection>();
|
||||
public ITable<QueueOffset> QueueOffsets => this.GetTable<QueueOffset>();
|
||||
}
|
||||
@@ -53,32 +53,24 @@ public class DbFactory : IDbFactory
|
||||
.UseMappingSchema(AnnotationsDbSchemaHolder.MappingSchema);
|
||||
|
||||
if (!File.Exists(_annConfig.AnnotationsDbFile))
|
||||
CreateDb();
|
||||
SQLiteConnection.CreateFile(_annConfig.AnnotationsDbFile);
|
||||
RecreateTables();
|
||||
|
||||
_fileConnection.Open();
|
||||
_fileConnection.BackupDatabase(_memoryConnection, "main", "main", -1, null, -1);
|
||||
}
|
||||
|
||||
private void CreateDb()
|
||||
private void RecreateTables()
|
||||
{
|
||||
SQLiteConnection.CreateFile(_annConfig.AnnotationsDbFile);
|
||||
using var db = new AnnotationsDb(_fileDataOptions);
|
||||
db.CreateTable<Annotation>();
|
||||
db.CreateTable<AnnotationQueueRecord>();
|
||||
db.CreateTable<Detection>();
|
||||
db.CreateTable<QueueOffset>();
|
||||
db.QueueOffsets.BulkCopy(new List<QueueOffset>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Offset = 0,
|
||||
QueueName = Constants.MQ_ANNOTATIONS_QUEUE
|
||||
},
|
||||
new()
|
||||
{
|
||||
Offset = 0,
|
||||
QueueName = Constants.MQ_ANNOTATIONS_CONFIRM_QUEUE
|
||||
}
|
||||
});
|
||||
var schema = db.DataProvider.GetSchemaProvider().GetSchema(db);
|
||||
var existingTables = schema.Tables.Select(x => x.TableName).ToHashSet();
|
||||
if (!existingTables.Contains(Constants.ANNOTATIONS_TABLENAME))
|
||||
db.CreateTable<Annotation>();
|
||||
if (!existingTables.Contains(Constants.DETECTIONS_TABLENAME))
|
||||
db.CreateTable<Detection>();
|
||||
if (!existingTables.Contains(Constants.ANNOTATIONS_QUEUE_TABLENAME))
|
||||
db.CreateTable<AnnotationQueueRecord>();
|
||||
}
|
||||
|
||||
public async Task<T> Run<T>(Func<AnnotationsDb, Task<T>> func)
|
||||
@@ -138,6 +130,7 @@ public static class AnnotationsDbSchemaHolder
|
||||
|
||||
builder.Entity<AnnotationQueueRecord>()
|
||||
.HasTableName(Constants.ANNOTATIONS_QUEUE_TABLENAME)
|
||||
.HasPrimaryKey(x => x.Id)
|
||||
.Property(x => x.AnnotationNames)
|
||||
.HasDataType(DataType.NVarChar)
|
||||
.HasConversion(list => JsonConvert.SerializeObject(list), str => JsonConvert.DeserializeObject<List<string>>(str) ?? new List<string>());
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace Azaion.Common.Database;
|
||||
|
||||
public class QueueOffset
|
||||
{
|
||||
public string QueueName { get; set; } = null!;
|
||||
public ulong Offset { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user