This commit is contained in:
@@ -228,6 +228,16 @@ namespace AyaNova.Biz
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Make a log entry for a job
|
||||
/// (no context version)
|
||||
/// </summary>
|
||||
/// <param name="jobId"></param>
|
||||
/// <param name="statusText"></param>
|
||||
internal static OpsJobLog LogJob(Guid jobId, string statusText)
|
||||
{
|
||||
return LogJob(jobId, statusText);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make a log entry for a job
|
||||
@@ -235,8 +245,10 @@ namespace AyaNova.Biz
|
||||
/// <param name="jobId"></param>
|
||||
/// <param name="statusText"></param>
|
||||
/// <param name="ct"></param>
|
||||
internal static OpsJobLog LogJob(Guid jobId, string statusText, AyContext ct)
|
||||
internal static OpsJobLog LogJob(Guid jobId, string statusText, AyContext ct = null)
|
||||
{
|
||||
if (ct == null)
|
||||
ct = ServiceProviderProvider.DBContext;
|
||||
if (string.IsNullOrWhiteSpace(statusText))
|
||||
statusText = "No status provided";
|
||||
OpsJobLog newObj = new OpsJobLog();
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace AyaNova.Biz
|
||||
//Get the import filename from the jsondata
|
||||
JObject jobData = JObject.Parse(job.JobInfo);
|
||||
var seedLevel = (Seeder.SeedLevel)jobData["seedLevel"].Value<int>();
|
||||
Seeder.SeedDatabase(seedLevel);
|
||||
Seeder.SeedDatabase(seedLevel, job.GId);
|
||||
JobsBiz.LogJob(job.GId, "Finished.", ct);
|
||||
JobsBiz.UpdateJobStatus(job.GId, JobStatus.Completed, ct);
|
||||
await Task.CompletedTask;
|
||||
|
||||
@@ -14,15 +14,22 @@ namespace AyaNova.Util
|
||||
|
||||
public static class Seeder
|
||||
{
|
||||
|
||||
public enum SeedLevel { SmallOneManShopTrialDataSet, MediumLocalServiceCompanyTrialDataSet, LargeCorporateMultiRegionalTrialDataSet, HugeForLoadTest };
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
//Seed database for trial and testing purposes
|
||||
//
|
||||
|
||||
public static void SeedDatabase(SeedLevel slevel)
|
||||
{
|
||||
SeedDatabase(slevel, Guid.Empty);
|
||||
}
|
||||
|
||||
public static void SeedDatabase(SeedLevel slevel, Guid JobId)
|
||||
{
|
||||
bool LogJob = JobId != Guid.Empty;
|
||||
|
||||
ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("Seeder");
|
||||
ApiServerState apiServerState = (ApiServerState)ServiceProviderProvider.Provider.GetService(typeof(ApiServerState));
|
||||
|
||||
@@ -36,15 +43,16 @@ namespace AyaNova.Util
|
||||
|
||||
try
|
||||
{
|
||||
log.LogInformation("SEEDER: Seed data level - " + slevel.ToString());
|
||||
LogStatus(JobId, LogJob, log, $"SEEDER: Seed data level - {slevel.ToString()}");
|
||||
|
||||
//Only allow this in a trial database
|
||||
if (!AyaNova.Core.License.ActiveKey.TrialLicense)
|
||||
{
|
||||
throw new System.NotSupportedException("This database has a registered license key and can't be seeded.");
|
||||
var msg = "This database has a registered license key so it can't be seeded";
|
||||
LogStatus(JobId, LogJob, log, msg);
|
||||
throw new System.NotSupportedException(msg);
|
||||
}
|
||||
|
||||
log.LogInformation("Setting server state to OpsOnly");
|
||||
apiServerState.SetOpsOnly("Seeding database");
|
||||
|
||||
//Erase all the data except for the license, schema and the manager user
|
||||
@@ -123,8 +131,8 @@ namespace AyaNova.Util
|
||||
//this is a large corporation with multiple branches in multiple locations all in the same country
|
||||
//Each location has a full staff and corporate head office has an overarching staff member in charge of each location
|
||||
|
||||
//PERF
|
||||
log.LogInformation($"Seeding 279 user(s)....");
|
||||
//PERF
|
||||
LogStatus(JobId, LogJob, log, $"Seeding 279 user(s)....");
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
|
||||
@@ -172,18 +180,17 @@ namespace AyaNova.Util
|
||||
|
||||
//PERF
|
||||
watch.Stop();
|
||||
log.LogInformation($"279 Users seeded in {watch.ElapsedMilliseconds} ms");
|
||||
|
||||
LogStatus(JobId, LogJob, log, $"279 Users seeded in {watch.ElapsedMilliseconds} ms");
|
||||
|
||||
//5000 widgets
|
||||
log.LogInformation($"Seeding 5000 Widgets....");
|
||||
LogStatus(JobId, LogJob, log, $"Seeding 5,000 Widgets....");
|
||||
watch = new Stopwatch();
|
||||
watch.Start();
|
||||
GenSeedWidget(log, 5000);
|
||||
|
||||
//PERF
|
||||
watch.Stop();
|
||||
log.LogInformation($"5k Widgets seeded in {watch.ElapsedMilliseconds} ms");
|
||||
LogStatus(JobId, LogJob, log, $"5k Widgets seeded in {watch.ElapsedMilliseconds} ms");
|
||||
#endregion genlarge
|
||||
}
|
||||
break;
|
||||
@@ -195,7 +202,7 @@ namespace AyaNova.Util
|
||||
//It is acceptable for this seeding to take many hours as it would normally be used rarely
|
||||
|
||||
//PERF
|
||||
log.LogInformation($"Seeding 1,410 user(s)....");
|
||||
LogStatus(JobId, LogJob, log, $"Seeding 1,410 user(s)....");
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
|
||||
@@ -243,27 +250,27 @@ namespace AyaNova.Util
|
||||
|
||||
//PERF
|
||||
watch.Stop();
|
||||
log.LogInformation($"1,410 Users seeded in {watch.ElapsedMilliseconds} ms");
|
||||
|
||||
LogStatus(JobId, LogJob, log, $"1,410 Users seeded in {watch.ElapsedMilliseconds} ms");
|
||||
|
||||
//20000 widgets
|
||||
log.LogInformation($"Seeding 20,000 Widgets....");
|
||||
LogStatus(JobId, LogJob, log, $"Seeding 20,000 Widgets....");
|
||||
watch = new Stopwatch();
|
||||
watch.Start();
|
||||
GenSeedWidget(log, 20000);
|
||||
watch.Stop();
|
||||
log.LogInformation($"20k Widgets seeded in {watch.ElapsedMilliseconds} ms");
|
||||
LogStatus(JobId, LogJob, log, $"20k Widgets seeded in {watch.ElapsedMilliseconds} ms");
|
||||
#endregion genhuge
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
log.LogInformation("Seeding completed successfully");
|
||||
LogStatus(JobId, LogJob, log, "Seeding completed successfully");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.LogError(ex, "Seeder:SeedDatabase error during ops");
|
||||
if (LogJob)
|
||||
JobsBiz.LogJob(JobId, $"Seeder:SeedDatabase error during ops\r\n{ex.Message}");
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
@@ -274,6 +281,15 @@ namespace AyaNova.Util
|
||||
}
|
||||
|
||||
|
||||
//Log the status and also job if it's run via job
|
||||
private static void LogStatus(Guid JobId, bool LogJob, ILogger log, string msg)
|
||||
{
|
||||
log.LogInformation(msg);
|
||||
if (LogJob)
|
||||
JobsBiz.LogJob(JobId, msg);
|
||||
}
|
||||
|
||||
|
||||
public static long RUNNING_COUNT = 0;
|
||||
public static string Uniquify(string s)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user