diff --git a/.vscode/launch.json b/.vscode/launch.json index d1ace0ad..8ad5b14a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -48,7 +48,7 @@ "AYANOVA_DATA_PATH": "c:\\temp\\ravendata", "AYANOVA_USE_URLS": "http://*:7575;", //"AYANOVA_PERMANENTLY_ERASE_DATABASE":"true", - "AYANOVA_SERVER_TEST_MODE": "false", + "AYANOVA_SERVER_TEST_MODE": "true", "AYANOVA_SERVER_TEST_MODE_TZ_OFFSET": "-8", //"AYANOVA_REPORT_RENDERING_TIMEOUT":"1", "AYANOVA_SERVER_TEST_MODE_SEEDLEVEL": "small", diff --git a/server/AyaNova/generator/CoreJobCustomerNotify.cs b/server/AyaNova/generator/CoreJobCustomerNotify.cs index e83c25ec..6c5ae458 100644 --- a/server/AyaNova/generator/CoreJobCustomerNotify.cs +++ b/server/AyaNova/generator/CoreJobCustomerNotify.cs @@ -116,11 +116,11 @@ namespace AyaNova.Biz private static async Task DeliverCustomerNotificationSMTP(CustomerNotifyEvent ne, CustomerNotifySubscription subscription, string deliveryAddress, AyContext ct) { - var DeliveryLogItem = new NotifyDeliveryLog() + var DeliveryLogItem = new CustomerNotifyDeliveryLog() { Processed = DateTime.UtcNow, ObjectId = ne.ObjectId, - NotifySubscriptionId = ne.CustomerNotifySubscriptionId, + CustomerNotifySubscriptionId = ne.CustomerNotifySubscriptionId, Fail = false }; @@ -288,7 +288,7 @@ namespace AyaNova.Biz ct.CustomerNotifyEvent.Remove(ne); //add delivery log item - await ct.NotifyDeliveryLog.AddAsync(DeliveryLogItem); + await ct.CustomerNotifyDeliveryLog.AddAsync(DeliveryLogItem); await ct.SaveChangesAsync(); } } diff --git a/server/AyaNova/generator/CoreNotificationSweeper.cs b/server/AyaNova/generator/CoreNotificationSweeper.cs index 55e95b30..b4fd6728 100644 --- a/server/AyaNova/generator/CoreNotificationSweeper.cs +++ b/server/AyaNova/generator/CoreNotificationSweeper.cs @@ -45,6 +45,10 @@ namespace AyaNova.Biz //Note: also has bearing on CoreJobPMInventoryCheck which uses notifydeliverylog to check if pm inventory notify has been done it's one time already await ct.Database.ExecuteSqlInterpolatedAsync($"delete from anotifydeliverylog where processed < {dtDeleteCutoff}"); + //CustomerNotifyDeliveryLog - deletes all log items older than 90 days + await ct.Database.ExecuteSqlInterpolatedAsync($"delete from acustomernotifydeliverylog where processed < {dtDeleteCutoff}"); + + } lastSweep = DateTime.UtcNow; } diff --git a/server/AyaNova/models/AyContext.cs b/server/AyaNova/models/AyContext.cs index 72503dc6..8d1d9c43 100644 --- a/server/AyaNova/models/AyContext.cs +++ b/server/AyaNova/models/AyContext.cs @@ -129,6 +129,7 @@ namespace AyaNova.Models public virtual DbSet CustomerNotifySubscription { get; set; } public virtual DbSet CustomerNotifyEvent { get; set; } + public virtual DbSet CustomerNotifyDeliveryLog { get; set; } diff --git a/server/AyaNova/models/CustomerNotifyDeliveryLog.cs b/server/AyaNova/models/CustomerNotifyDeliveryLog.cs new file mode 100644 index 00000000..12cf0913 --- /dev/null +++ b/server/AyaNova/models/CustomerNotifyDeliveryLog.cs @@ -0,0 +1,41 @@ +using System; +using System.ComponentModel.DataAnnotations; +using Newtonsoft.Json; + +namespace AyaNova.Models +{ + //This model holds the Customer notification deliveries that have been attempted in the past 90 days (cleaned out by corenotifysweeper) + //it is used for verification / troubleshooting purposes from the OPS log + //and also used as a circuit breaker by the corejobnotify to ensure users are not spammed with identical messages + + public class CustomerNotifyDeliveryLog + { + public long Id { get; set; } + public uint Concurrency { get; set; } + + [Required] + public DateTime Processed { get; set; } + + public long ObjectId { get; set; } + + [Required] + public long CustomerNotifySubscriptionId { get; set; } + + [Required] + public bool Fail { get; set; } + public string Error { get; set; } + + + public CustomerNotifyDeliveryLog() + { + Processed = DateTime.UtcNow; + Fail = false; + ObjectId = 0; + } + + //linked entity + public CustomerNotifySubscription CustomerNotifySubscription { get; set; } + + }//eoc + +}//eons diff --git a/server/AyaNova/models/NotifyDeliveryLog.cs b/server/AyaNova/models/NotifyDeliveryLog.cs index 5f0cce68..0001f1ce 100644 --- a/server/AyaNova/models/NotifyDeliveryLog.cs +++ b/server/AyaNova/models/NotifyDeliveryLog.cs @@ -17,23 +17,17 @@ namespace AyaNova.Models public long Id { get; set; } public uint Concurrency { get; set; } +//public AyaType NotifyType { get; set; } +//public long CustomerNotifySubscriptionId {get;set;} + [Required] public DateTime Processed { get; set; } - //public AyaType AyaType { get; set; } + public long ObjectId { get; set; } - // [Required] - //public NotifyEventType EventType { get; set; } + [Required] public long NotifySubscriptionId { get; set; } - - // [Required] - // public long IdValue { get; set; } - //[Required] - // public decimal DecValue { get; set; } - // [Required] - // public long UserId { get; set; } - // [Required] - // public NotifyDeliveryMethod DeliveryMethod { get; set; } + [Required] public bool Fail { get; set; } public string Error { get; set; } @@ -43,10 +37,6 @@ namespace AyaNova.Models { Processed = DateTime.UtcNow; Fail = false; - - // IdValue = 0; - // DecValue = 0; - // AyaType = AyaType.NoType; ObjectId = 0; } diff --git a/server/AyaNova/util/AySchema.cs b/server/AyaNova/util/AySchema.cs index 2dd42d8b..5b6ab267 100644 --- a/server/AyaNova/util/AySchema.cs +++ b/server/AyaNova/util/AySchema.cs @@ -22,16 +22,16 @@ namespace AyaNova.Util //!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImportingAsync WHEN NEW TABLES ADDED!!!! private const int DESIRED_SCHEMA_LEVEL = 1; - internal const long EXPECTED_COLUMN_COUNT = 1355; - internal const long EXPECTED_INDEX_COUNT = 155; - internal const long EXPECTED_CHECK_CONSTRAINTS = 545; + internal const long EXPECTED_COLUMN_COUNT = 1361; + internal const long EXPECTED_INDEX_COUNT = 156; + internal const long EXPECTED_CHECK_CONSTRAINTS = 550; internal const long EXPECTED_FOREIGN_KEY_CONSTRAINTS = 201; internal const long EXPECTED_VIEWS = 11; internal const long EXPECTED_ROUTINES = 2; //!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImportingAsync WHEN NEW TABLES ADDED!!!! - ///////////////////////////////////////// (C1353:I155:CC542:FC201:V11:R2) + ///////////////////////////////////////// C1361:I156:CC550:FC201:V11:R2) /* @@ -1217,6 +1217,8 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); + "ayatype INTEGER NOT NULL, objectid BIGINT NOT NULL, name TEXT NOT NULL, eventtype INTEGER NOT NULL, customernotifysubscriptionid BIGINT NOT NULL REFERENCES acustomernotifysubscription(id) ON DELETE CASCADE, " + "customerid BIGINT NOT NULL REFERENCES acustomer (id) ON DELETE CASCADE, eventdate TIMESTAMPTZ NOT NULL, decvalue DECIMAL(38,18) NULL, message TEXT NOT NULL, subject TEXT NOT NULL)"); + await ExecQueryAsync("CREATE TABLE acustomernotifydeliverylog (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, processed TIMESTAMPTZ NOT NULL, " + + "objectid BIGINT NOT NULL, customernotifysubscriptionid BIGINT NOT NULL, fail BOOL NOT NULL, error TEXT)"); diff --git a/server/AyaNova/util/DbUtil.cs b/server/AyaNova/util/DbUtil.cs index 49dfb7c2..ff28d15b 100644 --- a/server/AyaNova/util/DbUtil.cs +++ b/server/AyaNova/util/DbUtil.cs @@ -464,6 +464,9 @@ namespace AyaNova.Util await EraseTableAsync("anotifyevent", conn); await EraseTableAsync("anotifydeliverylog", conn); await EraseTableAsync("anotifysubscription", conn); + await EraseTableAsync("acustomernotifyevent", conn); + await EraseTableAsync("acustomernotifydeliverylog", conn); + await EraseTableAsync("acustomernotifysubscription", conn); await EraseTableAsync("amemo", conn); await EraseTableAsync("areminder", conn);//depends on User