This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
todo: FAKER, is there a leak, do I need to dispose of it somehow, am I using it right?
|
todo: FAKER, is there a leak, do I need to dispose of it somehow, am I using it right?
|
||||||
(it appeared high in objects in allocated memory when investigating memory consumption)
|
(it appeared high in objects in allocated memory when investigating memory consumption)
|
||||||
|
|
||||||
|
todo: static hunt, look for anything declared static that doesn't need to be
|
||||||
|
|
||||||
todo: tag refcount
|
todo: tag refcount
|
||||||
Move this into a procedure, it's apparently quite slow now that I can see the metrics
|
Move this into a procedure, it's apparently quite slow now that I can see the metrics
|
||||||
|
|||||||
@@ -67,8 +67,8 @@ namespace AyaNova.Api.Controllers
|
|||||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "Current license is not a trial license key. Only a trial can be seeded."));
|
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "Current license is not a trial license key. Only a trial can be seeded."));
|
||||||
}
|
}
|
||||||
|
|
||||||
Seeder.SeedLevel seedLevel = Seeder.StringToSeedLevel(size);
|
Seeder.Level.SeedLevel seedLevel = Seeder.Level.StringToSeedLevel(size);
|
||||||
if (seedLevel == Seeder.SeedLevel.NotValid)
|
if (seedLevel == Seeder.Level.SeedLevel.NotValid)
|
||||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.NOT_FOUND, "size", "Valid values are \"small\", \"medium\", \"large\", \"huge\""));
|
return BadRequest(new ApiErrorResponse(ApiErrorCode.NOT_FOUND, "size", "Valid values are \"small\", \"medium\", \"large\", \"huge\""));
|
||||||
|
|
||||||
//Create the job here
|
//Create the job here
|
||||||
|
|||||||
@@ -572,8 +572,8 @@ namespace AyaNova
|
|||||||
_newLog.LogInformation($"Server test mode seeding, level is {ServerBootConfig.AYANOVA_SERVER_TEST_MODE_SEEDLEVEL}, tz offset is {ServerBootConfig.AYANOVA_SERVER_TEST_MODE_TZ_OFFSET}");
|
_newLog.LogInformation($"Server test mode seeding, level is {ServerBootConfig.AYANOVA_SERVER_TEST_MODE_SEEDLEVEL}, tz offset is {ServerBootConfig.AYANOVA_SERVER_TEST_MODE_TZ_OFFSET}");
|
||||||
AyaNova.Core.License.FetchKeyAsync(apiServerState, dbContext, _newLog).Wait();
|
AyaNova.Core.License.FetchKeyAsync(apiServerState, dbContext, _newLog).Wait();
|
||||||
//NOTE: For unit testing make sure the time zone is same as tester to ensure list filter by date tests will work because server is on same page as user in terms of time
|
//NOTE: For unit testing make sure the time zone is same as tester to ensure list filter by date tests will work because server is on same page as user in terms of time
|
||||||
var seed = new Util.SeederNew();
|
var seed = new Util.Seeder();
|
||||||
seed.SeedDatabaseAsync(SeederNew.Level.StringToSeedLevel(ServerBootConfig.AYANOVA_SERVER_TEST_MODE_SEEDLEVEL), ServerBootConfig.AYANOVA_SERVER_TEST_MODE_TZ_OFFSET).Wait();
|
seed.SeedDatabaseAsync(Seeder.Level.StringToSeedLevel(ServerBootConfig.AYANOVA_SERVER_TEST_MODE_SEEDLEVEL), ServerBootConfig.AYANOVA_SERVER_TEST_MODE_TZ_OFFSET).Wait();
|
||||||
}
|
}
|
||||||
//TESTING
|
//TESTING
|
||||||
|
|
||||||
|
|||||||
@@ -61,11 +61,12 @@ namespace AyaNova.Biz
|
|||||||
//basically any error condition during job processing should throw up an exception if it can't be handled
|
//basically any error condition during job processing should throw up an exception if it can't be handled
|
||||||
|
|
||||||
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running);
|
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running);
|
||||||
await JobsBiz.LogJobAsync(job.GId, $"Starting...");
|
await JobsBiz.LogJobAsync(job.GId, $"Starting...");
|
||||||
JObject jobData = JObject.Parse(job.JobInfo);
|
JObject jobData = JObject.Parse(job.JobInfo);
|
||||||
var seedLevel = (Seeder.SeedLevel)jobData["seedLevel"].Value<int>();
|
var seedLevel = (Seeder.Level.SeedLevel)jobData["seedLevel"].Value<int>();
|
||||||
var timeZoneOffset = jobData["timeZoneOffset"].Value<decimal>();
|
var timeZoneOffset = jobData["timeZoneOffset"].Value<decimal>();
|
||||||
await Seeder.SeedDatabaseAsync(seedLevel, job.GId, timeZoneOffset);
|
var seed = new Util.Seeder();
|
||||||
|
await seed.SeedDatabaseAsync(seedLevel, job.GId, timeZoneOffset);
|
||||||
await JobsBiz.LogJobAsync(job.GId, "Finished.");
|
await JobsBiz.LogJobAsync(job.GId, "Finished.");
|
||||||
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed);
|
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ using System.Collections.Generic;
|
|||||||
using AyaNova.Models;
|
using AyaNova.Models;
|
||||||
using AyaNova.Biz;
|
using AyaNova.Biz;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Bogus;
|
using Bogus;
|
||||||
using AyaNova.Api.ControllerHelpers;
|
using AyaNova.Api.ControllerHelpers;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@@ -13,42 +12,47 @@ using System.Diagnostics;
|
|||||||
namespace AyaNova.Util
|
namespace AyaNova.Util
|
||||||
{
|
{
|
||||||
|
|
||||||
public static class Seeder
|
public class Seeder
|
||||||
{
|
{
|
||||||
public enum SeedLevel { NotValid, SmallOneManShopTrialDataSet, MediumLocalServiceCompanyTrialDataSet, LargeCorporateMultiRegionalTrialDataSet, HugeForLoadTest };
|
public static class Level
|
||||||
public static int SeededUserCount = 0;
|
|
||||||
|
|
||||||
public static SeedLevel StringToSeedLevel(string size)
|
|
||||||
{
|
{
|
||||||
switch (size.ToLowerInvariant())
|
public enum SeedLevel { NotValid, SmallOneManShopTrialDataSet, MediumLocalServiceCompanyTrialDataSet, LargeCorporateMultiRegionalTrialDataSet, HugeForLoadTest };
|
||||||
|
public static SeedLevel StringToSeedLevel(string size)
|
||||||
{
|
{
|
||||||
case "small":
|
switch (size.ToLowerInvariant())
|
||||||
return SeedLevel.SmallOneManShopTrialDataSet;
|
{
|
||||||
|
case "small":
|
||||||
|
return SeedLevel.SmallOneManShopTrialDataSet;
|
||||||
|
|
||||||
case "medium":
|
case "medium":
|
||||||
return SeedLevel.MediumLocalServiceCompanyTrialDataSet;
|
return SeedLevel.MediumLocalServiceCompanyTrialDataSet;
|
||||||
|
|
||||||
case "large":
|
case "large":
|
||||||
return SeedLevel.LargeCorporateMultiRegionalTrialDataSet;
|
return SeedLevel.LargeCorporateMultiRegionalTrialDataSet;
|
||||||
|
|
||||||
case "huge":
|
case "huge":
|
||||||
return SeedLevel.HugeForLoadTest;
|
return SeedLevel.HugeForLoadTest;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return SeedLevel.NotValid;
|
return SeedLevel.NotValid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int SeededUserCount = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
//Seed database for trial and testing purposes
|
//Seed database for trial and testing purposes
|
||||||
//
|
//
|
||||||
|
|
||||||
public static async Task SeedDatabaseAsync(SeedLevel slevel, Decimal timeZoneOffset)
|
public async Task SeedDatabaseAsync(Level.SeedLevel slevel, Decimal timeZoneOffset)
|
||||||
{
|
{
|
||||||
await SeedDatabaseAsync(slevel, Guid.Empty, timeZoneOffset);
|
await SeedDatabaseAsync(slevel, Guid.Empty, timeZoneOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task SeedDatabaseAsync(SeedLevel slevel, Guid JobId, Decimal timeZoneOffset)
|
public async Task SeedDatabaseAsync(Level.SeedLevel slevel, Guid JobId, Decimal timeZoneOffset)
|
||||||
{
|
{
|
||||||
bool LogJob = JobId != Guid.Empty;
|
bool LogJob = JobId != Guid.Empty;
|
||||||
SeededUserCount = 0;
|
SeededUserCount = 0;
|
||||||
@@ -182,7 +186,7 @@ namespace AyaNova.Util
|
|||||||
//log.LogInformation("Seeding all other data");
|
//log.LogInformation("Seeding all other data");
|
||||||
switch (slevel)
|
switch (slevel)
|
||||||
{
|
{
|
||||||
case SeedLevel.SmallOneManShopTrialDataSet:
|
case Level.SeedLevel.SmallOneManShopTrialDataSet:
|
||||||
{
|
{
|
||||||
#region GenSmall
|
#region GenSmall
|
||||||
//This is for a busy but one man shop with a single office person handling stuff back at the shop
|
//This is for a busy but one man shop with a single office person handling stuff back at the shop
|
||||||
@@ -211,7 +215,7 @@ namespace AyaNova.Util
|
|||||||
#endregion gensmall
|
#endregion gensmall
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SeedLevel.MediumLocalServiceCompanyTrialDataSet:
|
case Level.SeedLevel.MediumLocalServiceCompanyTrialDataSet:
|
||||||
{
|
{
|
||||||
#region GenMedium
|
#region GenMedium
|
||||||
//This is for a typical AyaNova medium busy shop
|
//This is for a typical AyaNova medium busy shop
|
||||||
@@ -273,7 +277,7 @@ namespace AyaNova.Util
|
|||||||
#endregion genmedium
|
#endregion genmedium
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SeedLevel.LargeCorporateMultiRegionalTrialDataSet:
|
case Level.SeedLevel.LargeCorporateMultiRegionalTrialDataSet:
|
||||||
{
|
{
|
||||||
#region GenLarge
|
#region GenLarge
|
||||||
//this is a large corporation with multiple branches in multiple locations all in the same country
|
//this is a large corporation with multiple branches in multiple locations all in the same country
|
||||||
@@ -350,7 +354,7 @@ namespace AyaNova.Util
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SeedLevel.HugeForLoadTest:
|
case Level.SeedLevel.HugeForLoadTest:
|
||||||
{
|
{
|
||||||
#region GenHuge
|
#region GenHuge
|
||||||
//this is the HUGE dataset for load and other testing
|
//this is the HUGE dataset for load and other testing
|
||||||
@@ -446,7 +450,7 @@ namespace AyaNova.Util
|
|||||||
|
|
||||||
|
|
||||||
//Log the status and also job if it's run via job
|
//Log the status and also job if it's run via job
|
||||||
private static async Task LogStatusAsync(Guid JobId, bool LogJob, ILogger log, string msg)
|
private async Task LogStatusAsync(Guid JobId, bool LogJob, ILogger log, string msg)
|
||||||
{
|
{
|
||||||
log.LogInformation(msg);
|
log.LogInformation(msg);
|
||||||
if (LogJob)
|
if (LogJob)
|
||||||
@@ -454,16 +458,16 @@ namespace AyaNova.Util
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static long RUNNING_COUNT = 0;
|
public long RUNNING_COUNT = 0;
|
||||||
public static string Uniquify(string s)
|
public string Uniquify(string s)
|
||||||
{
|
{
|
||||||
return s + " " + (++RUNNING_COUNT).ToString();
|
return s + " " + (++RUNNING_COUNT).ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static string[] TagSet = new[] { "red", "orange", "yellow", "green", "blue", "indigo", "violet", "brown", "black", "white", "silver", "gold", "fuchsia", "jade", "mauve", "purple", "quince", "xanthic", "zebra", "zone0", "zone1", "zone2", "zone3", "zone4", "zone5", "zone6", "zone7", "zone8", "zone9" };
|
private string[] TagSet = new[] { "red", "orange", "yellow", "green", "blue", "indigo", "violet", "brown", "black", "white", "silver", "gold", "fuchsia", "jade", "mauve", "purple", "quince", "xanthic", "zebra", "zone0", "zone1", "zone2", "zone3", "zone4", "zone5", "zone6", "zone7", "zone8", "zone9" };
|
||||||
|
|
||||||
private static List<string> RandomTags(Faker f)
|
private List<string> RandomTags(Faker f)
|
||||||
{
|
{
|
||||||
|
|
||||||
var t = f.PickRandom(TagSet, f.Random.Int(1, 5));//pick up to 5 tags to apply
|
var t = f.PickRandom(TagSet, f.Random.Int(1, 5));//pick up to 5 tags to apply
|
||||||
@@ -473,7 +477,7 @@ namespace AyaNova.Util
|
|||||||
//////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
//Seed test data for integration tests
|
//Seed test data for integration tests
|
||||||
//
|
//
|
||||||
public static async Task SeedKnownUsersAsync(ILogger log)
|
public async Task SeedKnownUsersAsync(ILogger log)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -528,7 +532,7 @@ namespace AyaNova.Util
|
|||||||
/// Generate seed user with active=true
|
/// Generate seed user with active=true
|
||||||
/// (override to save typing)
|
/// (override to save typing)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static async Task GenSeedUserAsync(ILogger log, int count, AuthorizationRoles roles, UserType userType, string login, string password, List<string> tags = null)
|
public async Task GenSeedUserAsync(ILogger log, int count, AuthorizationRoles roles, UserType userType, string login, string password, List<string> tags = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -542,7 +546,7 @@ namespace AyaNova.Util
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static async Task GenSeedUserAsync(ILogger log, int count, AuthorizationRoles roles, UserType userType,
|
public async Task GenSeedUserAsync(ILogger log, int count, AuthorizationRoles roles, UserType userType,
|
||||||
bool active = true, string login = null, string password = null, long translationId = 0, List<string> tags = null)
|
bool active = true, string login = null, string password = null, long translationId = 0, List<string> tags = null)
|
||||||
{
|
{
|
||||||
if (translationId == 0)
|
if (translationId == 0)
|
||||||
@@ -733,7 +737,7 @@ namespace AyaNova.Util
|
|||||||
//////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
//Seed widget for testing
|
//Seed widget for testing
|
||||||
//
|
//
|
||||||
public static async Task GenSeedWidgetAsync(ILogger log, int count)
|
public async Task GenSeedWidgetAsync(ILogger log, int count)
|
||||||
{
|
{
|
||||||
//this is 4 times slower than doing it inside the loop below
|
//this is 4 times slower than doing it inside the loop below
|
||||||
//seems counterintuitive but maybe it's to do with the db context not being refreshed?
|
//seems counterintuitive but maybe it's to do with the db context not being refreshed?
|
||||||
|
|||||||
Reference in New Issue
Block a user