This commit is contained in:
@@ -267,6 +267,11 @@ namespace Sockeye.Biz
|
|||||||
await SockBotProcessVendorNotifications.DoWorkAsync();
|
await SockBotProcessVendorNotifications.DoWorkAsync();
|
||||||
if (!KeepOnWorking()) return;
|
if (!KeepOnWorking()) return;
|
||||||
|
|
||||||
|
//SOCKBOT - PROCESS PURCHASES INTO LICENSES
|
||||||
|
await SockBotProcessPurchasesIntoLicenses.DoWorkAsync();
|
||||||
|
if (!KeepOnWorking()) return;
|
||||||
|
|
||||||
|
|
||||||
//JOB SWEEPER
|
//JOB SWEEPER
|
||||||
await CoreJobSweeper.DoWorkAsync();
|
await CoreJobSweeper.DoWorkAsync();
|
||||||
if (!KeepOnWorking()) return;
|
if (!KeepOnWorking()) return;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace Sockeye.Biz
|
|||||||
{
|
{
|
||||||
private static ILogger log = Sockeye.Util.ApplicationLogging.CreateLogger("SockBotProcessPurchasesIntoLicenses");
|
private static ILogger log = Sockeye.Util.ApplicationLogging.CreateLogger("SockBotProcessPurchasesIntoLicenses");
|
||||||
private static DateTime lastSweep = DateTime.MinValue;
|
private static DateTime lastSweep = DateTime.MinValue;
|
||||||
|
private static TimeSpan PROCESS_V7_AGE = new TimeSpan(0, 5, 0);//Don't process a v7 order until at least 5 minutes old as it doesn't always come in at once
|
||||||
#if (DEBUG)
|
#if (DEBUG)
|
||||||
private static TimeSpan PROCESS_EVERY_INTERVAL = new TimeSpan(0, 0, 30);//every 30 seconds during development
|
private static TimeSpan PROCESS_EVERY_INTERVAL = new TimeSpan(0, 0, 30);//every 30 seconds during development
|
||||||
#else
|
#else
|
||||||
@@ -47,39 +48,46 @@ namespace Sockeye.Biz
|
|||||||
using (AyContext ct = Sockeye.Util.ServiceProviderProvider.DBContext)
|
using (AyContext ct = Sockeye.Util.ServiceProviderProvider.DBContext)
|
||||||
{
|
{
|
||||||
|
|
||||||
//get a list of all actionable purchases
|
//get a lit of all actionable purchases grouped by customer id
|
||||||
var purchaseList = await ct.Purchase
|
var purchaseList = (await ct.Purchase
|
||||||
.Where(z => z.Processed == false
|
.Where(z => z.Processed == false
|
||||||
&& z.LicenseId == null
|
&& z.LicenseId == null
|
||||||
&& z.CustomerId != null
|
&& z.CustomerId != null
|
||||||
&& (z.PGroup == ProductGroup.AyaNova7 || z.PGroup == ProductGroup.RavenPerpetual || z.PGroup == ProductGroup.RavenSubscription))
|
&& (z.PGroup == ProductGroup.AyaNova7 || z.PGroup == ProductGroup.RavenPerpetual || z.PGroup == ProductGroup.RavenSubscription))
|
||||||
.OrderBy(z => z.Id)
|
.OrderByDescending(z => z.PurchaseDate)
|
||||||
.ToListAsync();
|
.ToListAsync()).GroupBy(z => (long)z.CustomerId);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (var p in purchaseList)
|
foreach (var purchaseGroup in purchaseList)
|
||||||
{
|
{
|
||||||
log.LogDebug($"Processing purchase id:{p.Id},purchasedate:{p.PurchaseDate}, custid:{p.CustomerId}");
|
//vet the group if v7 to be sure no item is less than 5 minutes old to ensure multiple add-on's have all arrived from mycommerce
|
||||||
|
foreach(var purchase in purchaseGroup){
|
||||||
|
if (purchase.PGroup == ProductGroup.AyaNova7 && DateTime.UtcNow - purchase.PurchaseDate < PROCESS_V7_AGE)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
log.LogDebug($"Processing purchase id:{purchaseGroup[0].Id},purchasedate:{purchaseGroup.PurchaseDate}, custid:{purchaseGroup.CustomerId}");
|
||||||
|
|
||||||
//if v7 product group the purchase must be more than 5 minutes old to account for mycommerce trickling in add-on bits to a v7 order
|
//if v7 product group the purchase must be more than 5 minutes old to account for mycommerce trickling in add-on bits to a v7 order
|
||||||
//(I went over old sales, mycommerce has at most 2 minutes variance in multiple item order on same day with the exception of unusual situations like where part
|
//(I went over old sales, mycommerce has at most 2 minutes variance in multiple item order on same day with the exception of unusual situations like where part
|
||||||
//of an order was on an invalid credit card or not updated in one case, another was a refund and purchase of alternate item etc)
|
//of an order was on an invalid credit card or not updated in one case, another was a refund and purchase of alternate item etc)
|
||||||
//So in the normal course of things going to assume the best and check further down if something seems missing from last license
|
//So in the normal course of things going to assume the best and check further down if something seems missing from last license
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(p.VendorData))
|
|
||||||
|
if (string.IsNullOrWhiteSpace(purchaseGroup.VendorData))
|
||||||
{
|
{
|
||||||
var err = $"VendorNotification record {p.Id}-{p.Created} has no vendor data";
|
var err = $"VendorNotification record {purchaseGroup.Id}-{purchaseGroup.Created} has no vendor data";
|
||||||
await NotifyEventHelper.AddOpsProblemEvent("SockBotProcessPurchasesIntoLicenses: " + err);
|
await NotifyEventHelper.AddOpsProblemEvent("SockBotProcessPurchasesIntoLicenses: " + err);
|
||||||
log.LogError(err);
|
log.LogError(err);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//Parse json vendordata
|
//Parse json vendordata
|
||||||
if (await ParseVendorNotificationData(p, ct, log))
|
if (await ParseVendorNotificationData(purchaseGroup, ct, log))
|
||||||
{
|
{
|
||||||
//success, save vendornotification as processed
|
//success, save vendornotification as processed
|
||||||
p.Processed = DateTime.UtcNow;
|
purchaseGroup.Processed = DateTime.UtcNow;
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user